[Answered ]-Render cms page within another page


Just for a moment ignoring the idea of creating a custom plugin in order to do what you describe (ie, render a page’s placeholders programatically), the following might be a viable alternative, depending on what exactly you are trying to achieve…

You should be able, just in the template for your “outer” cms page (ie, the page within which you want to display the contents of another cms page), to get access to the current page like this:

{{ request.current_page }}

This is by virtue of the cms page middleware. So taking that a step further, you should be able to access the page’s placeholders like this:

{% for placeholder in request.current_page.placeholders %}
    {{ placeholder.render }}
{% endfor %}

That’s one way you could go about rendering a page’s placeholders “inside” another page.



I needed to render another page from within the template which could be accomplished with:

def render_page(context, page, default="base.html"):
    if not page:
        return loader.get_template(default).render(context)
    new_context = copy(context)
    new_context['request'] = copy(context['request'])
    new_context['request'].current_page = page
    new_context['current_page'] = page    
    new_context['has_change_permissions'] = page.has_change_permission(context['request'])
    new_context['has_view_permissions'] = page.has_view_permission(context['request'])
    if not new_context['has_view_permissions']:
         return loader.get_template(default).render(context)
    return loader.get_template(page.get_template()).render(new_context)

Leave a comment