Building a custom template for the wagtail StreamField
block I found myself in the situation that I need somehow pass the ID of the current block to the other views.
For instance when the URL is clicked in the particular block, the landing page view
must know exactly in which of the blocks the URL has been clicked. Then the view
can extract other information which is associated with the particular block but not necessarily visually present to the user.
My current strategy is using the snippets
, so I can pass the ID of the snippet
and the view
may obtain related but beforehand hidden data.
This works not so bad, but people have to edit the content in two places and I have to look at their sad faces.
It seems that the value
variable in the block template context is an instance of the wagtail.core.blocks.struct_block.StructValue
, which gives me access to all the fields of the block but it doesn't seem to reveal its footprint in the DB.
Further value
has an interesting attribute: value.block
, which seems like it's an instance of the actual model used to construct the block, but again I can't find anything useful like id
or pk
which would allow to identify that instance in the database.
Is there a way?
uuid4
). Can you elaborate more, how can I use it to extract field values? Furthermore, is iteration through theStreamField
necessary? It seems absolutely counter intuitive thing to do when you just need to insert one item, but I assumeinclude_block
does that internaly when it detects theStreamField
? – Richey