Forum

Thread tagged as: Question, Suggestions

Multiple Blocks in Templates

Hi, I have a simple Content template that outputs 2 columns on the front end. I want to allow the editor to choose from blocks (Text, Image, Button etc) for each column. Eg:

<div class="col-md-6">
  <perch:template path="content/blocks.html" />         
</div>
<div class="col-md-6">
  <perch:template path="content/blocks.html" />
</div>

But I can't do this because we can't have 2 <perch:blocks> sets in the same template.

Is multiple Blocks in Templates on the Roadmap for Perch, or does anyone have a workaround for this type of scenario? I imagine it's very common.

Simon Clay

Simon Clay 127 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

It's not on the roadmap currently, and it's not something we've heard of before.

You can use perch:before and perch:after in blocks too.

Simon Clay

Simon Clay 127 points

Thanks Drew, Unless I'm missing something obvious, I can't see how perch:before and perch:after can help achieve my code.

Simon,

If I'm understanding you correctly, can't you set your columns up as a repeater and then allow them to use the blocks?

Simon Clay

Simon Clay 127 points

Hi Kim,

I guess you mean 'Repeating Regions', rather than Repeaters (Blocks can't go in Repeaters). Unfortunately I'm already using the Repeating Regions to wrap the Blocks with <section> and <div>.

Simon Clay

Simon Clay 127 points

Drew, you mention using <perch:before> and <perch:after> in blocks, and wanted to check if I'm missing a trick?

I can't see any use for before and after in blocks at all. These two have the same effect, correct?

<perch:blocks>
  <perch:block type="text" label="Text">
  <perch:before>
  <!--*Before code here*-->
  </perch:before>
  <perch:content id="test" type="text" label="Text" />
  <perch:after>
  <!--*After code here*-->
  </perch:after>
  </perch:block>
</perch:blocks>

is the same as:

<perch:blocks>
  <perch:block type="text" label="Text">
  <!--*Before code here*-->
  <perch:content id="test" type="text" label="Text" />
  <!--*After code here*-->
  </perch:block>
</perch:blocks>

Could you give an example of where before and after would be useful in blocks? It might open possibilities of helping me achieve what I need.

Thanks.

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, sorry, you're right. I'm thinking of repeaters (which are all the same thing internally).