如何在base.html中使用Django CMS中的条件来检测页面是否是主页并向body标签添加一个唯一的类?我宁愿不复制base而只是添加一个类,这样我就可以在主页上以不同的方式处理一些样式。
答案 0 :(得分:1)
这取决于您构建网页的方式。
我选择创建网页作为“家庭”的孩子。页面,所以对页面标题使用这样的东西;
{% if request.current_page.get_ancestors|length <= 1 %}
<h1>{{ request.current_page.get_page_title }}</h1>
{% else %}
{% for ance in request.current_page.get_ancestors %}
{% if ance.depth == 2 %}
<h1>{{ ance.get_page_title }}</h1>
{% endif %}
{% endfor %}
{% endif %}
所以你可以这样做;
<body class="{% if request.current_page.get_ancestors|length <= 1 %}base{% endif %}">