Forum

Thread tagged as: Question, Problem

Blocks and ids outside them

I might be being slow but is it not possible to reuse an id from outside a blocked section like in a normal template?

e.g. if I have <h4><perch:content id="title" type="text" label="Title" required="true" title="true" /></h4> before some blocks, can I not get the value of "title" within the blocks themselves?

What I'm actually trying to do is set up a multiple-item region where the individual items have a Title and a Date a bit like a small blog but just using perch... using blocks adds another level of flexibility as long as I can use the title and the date later on in the blocks themselves. I especially wanted to use them to generate titles for images included in the posts.

Perhaps I should do this in the blog app anyway but I'd still like to know if it's something silly I've done wrong at the moment!

This is the template code at the moment:

<article>
<h4><perch:content id="title" type="text" label="Title" required="true" title="true" /></h4>
<h5><perch:content id="date" type="date" label="Date" format="d F Y" required="true" /></h5>
<perch:blocks>      
    <perch:block type="text" label="Text">
        <perch:content id="text" type="textarea" label="Text" textile="true" editor="markitup" size="m" required="true" />
    </perch:block>
    <perch:block type="image" label="Picture">
        <p><a class="fancybox" rel="<perch:content id="date" format="dmy" />" href="<perch:content id="image" type="image" label="Picture" />" title="<perch:content id="title" /> - <perch:content id="date" />"><img src="<perch:content id="image" type="image" label="Picture" width="490" />" width="490" alt="<perch:content id="title" /> - <perch:content id="date" format="d F Y" />"></a></p>
        </perch:block>
</perch:blocks>
Owain Browne

Owain Browne 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Blocks have their own scope, just like repeaters. We have a feature planned to enable you to optionally bring the parent's content into scope, but it's not possible currently.

Thanks for clarifying, I suspected it might be the case but couldn't confirm it reading the docs. There's no real need for blocks as such for this purpose anyway so I'll just use an old method to do what I need.

But I think it would be useful to be able to bring fields from outside of repeaters and blocks down a level as it were even if it were only a small subset of them for precisely this sort of case, where a section built up out of Blocks or repeaters makes up a post or an article and has a title and a date that might be useful to use again automatically...

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, we'll add it - it works with repeaters currently but not blocks.