Wagtail: Rendering tags from Fieldblock

In your template, the line

{% for tag in page.services.get_tags %}

would be trying to access a property named get_tags on the ‘services’ field of the page. However, get_tags isn’t defined there – it’s defined as a property of the page object – so this line should be

{% for tag in page.get_tags %}

Secondly, in the line

tags_all = [block.value.entries.get('tags', '').split(',') for block in self]

you’re intending to loop over all the items in the StreamField, but the self in for block in self refers to the page object. This should be for block in self.services.

Finally, in the same line, block.value will give you the value of each block, which in this case will be a dictionary of two items, entries and tags. If you wanted to access entries (the PortfolioBlock), you would write block.value['entries'] or block.value.get('entries') rather than block.value.entries – but really you don’t want that, you want to access the tags item instead – so block.value.entries.get('tags', '').split(',') should be block.value.get('tags', '').split(',').

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top