简体   繁体   中英

How to render placeholders from a django-cms custom templatetag?

I've made a simple template tag to list child pages in a django-cms site. It's working fine except for the fact that I have not been able to render the child pages placeholders in the template tag itself.

The following is my code for the template tag.

subpages.py

from cms.models import Page
from cms.utils.page_resolver import get_page_from_path

from django import template


register = template.Library()


@register.inclusion_tag('subpages.html', takes_context = True)
def get_news_items( context ):
    request = context['request']
    subpages = request.current_page.children.filter(published=True)
    return {'subpages':subpages}

subpages.html

{% load cms_tags menu_tags placeholder_tags %}
<ul>
{% for item in subpages %}
    <li><a href="/{{ item.get_path }}">{{ item.get_title }}</a>
        {% render_placeholder subtitle %}
    </li>
{% endfor %}
</ul>

I've tried some alternatives to *render_placeholder* but without luck.

How would be the correct way to get the placeholder rendered?

This is only a (untested) suggestion, but try passing the context along to the template:

@register.inclusion_tag('subpages.html', takes_context = True)
def get_news_items( context ):
    request = context['request']
    subpages = request.current_page.children.filter(published=True)
    context.update({'subpages':subpages})
    return context

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM