Home Wagtail / Django ListBlock Behavior
Reply: 0

Wagtail / Django ListBlock Behavior

user1894
1#
user1894 Published in May 22, 2018, 9:20 pm

I am facing a wired situation, using wagtail.

My Models :

class SlideBlock(blocks.StructBlock):
    image = ImageChooserBlock()
    caption = blocks.CharBlock(required=False)

class Meta:
    template = 'home/blocks/carousel.html'

class HomePageIndex(Page):
    body = StreamField([
        ('head', blocks.TextBlock(classname="full title")),
        ('text', blocks.RichTextBlock()),
        ('html', blocks.RawHTMLBlock()),
        ('slider', blocks.ListBlock(SlideBlock()))
    ], blank=True)

    content_panels = Page.content_panels + [
        StreamFieldPanel('body'),
    ]

    # parent_page_types = []
    subpage_types = ['home.HomePageIndex',
                     'blog.BlogPageIndex',
                     'blog.BlogTagPageIndex']

My Template (MAIN) :

{% with blocks=self.body %}

{% for block in blocks %}

    <section>
        {% elif block.block_type == 'slider' %}
            in
            <!-- Gate to an nested template -->
            {% include_block block %}
            out
        {% else %}
            block-type not supported
        {% endif %}
    </section>

{% endfor %}
</article>
{% endwith %}

My Template (nested) :

<div>
    <div>

        {% for x in block.value %}

            <div class="carousel-item">
                {% image x.image max-1920x1080 class="d-block w-100" alt="Slide" %}
            </div>
        {% endfor %}
    </div>
</div>

Inside my database i use some test-data for testing reasons... But for some weired reason the nested template is called, as much data is inside my database. So i am not able to iterate over the ListBlock propertly. The output of the given example produces wired repeating outputs...

What did i miss / oversee?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.28122 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO