question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide page in the context of StreamField blocks

See original GitHub issue

I came across the limitation that the page is missing in the context of related StreamField blocks when rendering the blocks template several times. A typical use case is when you need to implement an intro block, where the page title and author should be displayed.

So far I was not able to solve this as a complete StreamField block. My implementation is a StreamField block anyway, but not using the blocks rendering mechanism. Instead I check for this block type and call a template with {% include %} and the necessary data as parameters.

The hurdle occurs in the majority of cases when you need to display data from builtin fields of Wagtails Page model. Otherwise you would be able to design it like it should be.

This issue is opened in addition to #1743 to clearly separate the discussion between the different requirements to have request and page available in the template context. I fully agree with https://github.com/torchbox/wagtail/issues/1743#issuecomment-144029475, though.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
BertrandBordagecommented, Apr 11, 2016

I agree, and the parent block (if any) would also be extremely useful in a lot of cases.

0reactions
gasmancommented, Jul 6, 2016

Closing this now, as the specific issue described here is fixed by #2786 (even if there is further work to do on the feature as a whole).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use StreamField for mixed content
StreamField provides a content editing model suitable for pages that do not follow a ... return context class Meta: template = 'myapp/blocks/event.html'.
Read more >
Freeform page content using StreamField — Wagtail 2.2.2 ...
In this model, these different content types are represented as a sequence of 'blocks', which can be repeated and arranged in any order....
Read more >
Wagtail page context in Streamfield template - Stack Overflow
I have StructBlock with it's own template, within a StreamField. I'm trying to access the page object from ...
Read more >
django-streamfield - PyPI
Add extra context to blocks. Supose, you need to add some data to blocks from global context. Instead of using render property in...
Read more >
How to use StreamField in Wagtail - AccordBox
StreamField provides a flexible way for us to construct content. ... import StreamField from .blocks import BodyBlock class PostPage(Page): ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found