0

I have a wagtail blog page and I want display a list of child pages, including the dates, title and intro. Currently only the title of the children is being displayed.

The

tags that contain page.date and page.intro are empty when rendered.

Here is the model for blog page:

class BlogPost(Page):
    date = models.DateField("Post date")
    intro = models.CharField(max_length=250)
    body = RichTextField(blank=True)

    search_fields = Page.search_fields + [
        index.SearchField('intro'),
        index.SearchField('body'),
    ]

    promote_panels = Page.promote_panels + [
        FieldPanel('intro'),
    ]

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

    class Meta:
        # order on primary key to make sure it's unique
        ordering = ('title', 'pk')

blog_index_page.html

{% extends "base.html" %}



{% load static wagtailcore_tags menu_tags %}


{% block content %}

    <h1>{{ page.title }}</h1>

    <div class="intro">{{ page.intro|richtext }}</div>

    <div class="list-of-previews">

      {% for page in self.get_children %}

        <div class="blog-post-preview">

          <p>{{ page.date }}</p>

          <a href="{{ page.url }}">{{ page.title }}</a>

          <p>{{ page.intro }}</p> 

        </div>

      {% endfor %}

    </div>

{% endblock %}

Blog Index Model

class BlogIndexPage(Page):
    intro = RichTextField(blank=True)

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

I would like to be able to display page.date and page.intro

Bryan D
  • 1
  • 2
  • Post your `BlogIndexPage` model. – Dan Swain Jul 23 '19 at 13:11
  • 1
    Possible duplicate of [Wagtail: Display a list of child pages inside a parent page](https://stackoverflow.com/questions/32429113/wagtail-display-a-list-of-child-pages-inside-a-parent-page) – gasman Jul 23 '19 at 13:21
  • Definitely a duplicate. The answer for this can be found from gasman's link and here as well https://stackoverflow.com/a/32436798/2074077 – Kalob Taulien Jul 23 '19 at 14:05
  • Oh you are right. When I tried this the first time I obviously made a typo because it works now. Thank you all. – Bryan D Jul 23 '19 at 16:00

0 Answers0