Twill: Rendering a child block within its parent on the front-end

Created on 30 Oct 2018  路  2Comments  路  Source: area17/twill

Hi,

I'm writing a front-end for my Twill project. I have successfully managed to output block content on a single module page on my front-end, but in the case of repeaters the child blocks render after their parent- whereas I want them to render between the parent's opening and closing HTML tags. How do I go about doing this?

Many thanks,
Seb

question

All 2 comments

Hi Seb,

you can opt-out from rendering children as separate views in repeater blocks when using the renderBlocks helper:

$item->renderBlocks(false)

Child blocks are then accessible through the $block->children relationship, so that you can loop over them inside the parent block view.

You do not have to opt-out from rendering children if you need to keep it somehow, you can render everything in the parent block and leave all child views empty, but that's a bit more clunky than simply opting-out to avoid having to create useless child views.

Perfect, thanks again! $block->children was what I was looking for.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

manuelsofia picture manuelsofia  路  4Comments

zipavlin picture zipavlin  路  3Comments

Gummibeer picture Gummibeer  路  5Comments

layout-lab picture layout-lab  路  5Comments

newvladimirov picture newvladimirov  路  5Comments