[Fixed]-Django / WagtailCMS โ€“ get attribute (eg body text) of child page using get_context

1๐Ÿ‘

โœ…

I got it working by changing the model to include .specific(), as suggested by @gasman. The working model is:

class ProjectsPage(Page):
body = RichTextField(blank=True)

content_panels = Page.content_panels + [
    FieldPanel('body', classname="full"),
]

def get_context(self, request):
    context = super(ProjectsPage, self).get_context(request)
    context['sub_pages'] = self.get_children().specific()
    print(context['sub_pages'])
    return context

And in the template:

{% with sub_pages as pages %}
    {% for page in pages %}
         {{ page.title }}
         {{ page.body }}
    {% endfor %}
{% endwith %}

The title and the body of the child page are now being rendered.

๐Ÿ‘คgeonaut

Leave a comment