【问题标题】:Can I use djangocms plugins in a conditional extended page?我可以在条件扩展页面中使用 djangocms 插件吗?
【发布时间】:2016-11-27 12:26:09
【问题描述】:

我的 djangocms 页面模板顶部有这个

{% extends request.user.is_authenticated|yesno:"member_template.html,base.html" %}

我的插件不适用于此设置。但是如果我这样做

{% extends "member_template.html" %}

我的插件有效。有没有办法解决这个问题?我想要那个条件。

【问题讨论】:

标签: django django-templates django-cms


【解决方案1】:

假设您在视图中使用渲染。

if request.user: base_file = "member_template.html"
else: base_file = base.html
render(request,'my_html.html',
               {'base_file' : base_file})

然后你的扩展标签看起来像:

{% extends base_file %}

【讨论】:

    【解决方案2】:

    你不能只放一个 if 语句吗?

    {% if user.is_authenticated %} {% extends "member_template.html" %}
    {% else %} {% extends "base.html" %}
    {% endif %}
    

    【讨论】:

    • 不,模板中的第一行必须是扩展的。如果我按照您的建议进行操作,则会出现错误。
    • 是的,对不起。但是extends还需要紧跟它扩展的文件或评估文件的变量,因此您需要一个标签或将其包含在上下文中
    • 你能举个例子吗?我对此一无所知。
    • @DharienCthaeh 你想过这个吗? stackoverflow.com/a/5381015/1757321
    • @DharienCthaeh 请参阅单独答案中的示例
    猜你喜欢
    • 2015-09-18
    • 2020-08-26
    • 1970-01-01
    • 2020-09-11
    • 2017-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多