覆盖 django cms 中的占位符?
嘿,我在我的一些自定义 cms 应用程序中使用 django cms 的占位符字段。基本上我想要实现的是不同模板中使用的相同占位符字段的特定样式和过滤器。
例如,如果我有一个看起来像这样的职位空缺模型:
from django.db import models
from cms.models.fields import PlaceholderField
# Create your models here.
class Vaccancy(models.Model):
title = models.CharField(max_length=255)
slug = models.SlugField(max_length=255, unique = True)
ref_number = models.CharField(max_length=255)
info = PlaceholderField('info')
active = models.BooleanField(default=True, verbose_name="posistion active?")
以及另一个也以类似方式利用占位符字段的模型。我希望我能做的是覆盖 tex.html 模板,然后有一些条件逻辑来检测占位符的名称,如下所示 {% ifequal 占位符“信息”%} {{ body|truncatewords:200|安全 }} {% endifequal %}
这样做的目的是让我可以指定不同的过滤器,例如 truncatewords 等,因为我不想将其应用于每个使用文本插件的占位符!
希望这足够清楚了!为任何帮助干杯!
Hey im using the placeholder fields from django cms in some of my custom cms apps. Basically what im trying to achieve is specific styles and filters for the same placeholder fields being used in different templates.
for example if i have a model for vacancies that looks something like this:
from django.db import models
from cms.models.fields import PlaceholderField
# Create your models here.
class Vaccancy(models.Model):
title = models.CharField(max_length=255)
slug = models.SlugField(max_length=255, unique = True)
ref_number = models.CharField(max_length=255)
info = PlaceholderField('info')
active = models.BooleanField(default=True, verbose_name="posistion active?")
and another model that also utilizes the placeholder field in a similar way. What i hoped i could do is overide the tex.html template then have some conditional logic to detect the name of the placeholder like so{% ifequal placeholder "info" %}
the aim of this is so i can specify different filters like truncatewords etc as i dont want to apply this to every placeholder that uses a text plugin!
{{ body|truncatewords:200|safe }}
{% endifequal %}
hope that was clear enough! cheers for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用占位符字段,则必须检查
placeholder.slot
,另请注意{% if placeholder.slot == "info" %}
看起来比如果相等
:DIf you use placeholder fields, you have to check for
placeholder.slot
, also note that{% if placeholder.slot == "info" %}
seems a bit nicer thanifequal
:D