Forum
including perch_item_index in a perch:content id
I have this repeater in a blocks template:
<perch:repeater id="images16" label="Images" scope-parent="true" max="6">
<div id="p7OPMpn_16_<perch:content id="perch_item_index" />" class="opm-panel">
<div class="opm-panel-content">
<img alt="" src="<perch:content id="image16" type="image" label="Image" width="640" height="640" required="false" />" style="padding-top:16px;" />
</div>
</div>
</perch:repeater>
and I want to append perch_item_index to the perch:content id currently image16 so that it becomes image16-1, image16-2 etc. It doesn't work. Is there a way to do this?
I am using it earlier in the template like this:
<perch:if exists="image16-1"><li><a id="p7OPMtg_16_1" href="#">Trigger Text</a></li></perch:if> ...
In what way doesn't it work?
What I want to do is this (adding appending <perch:content id="perch_item_index" /> to the content id in src) like this but it doesn't work the <img ... /> isn't output to the page.
I think you want something more like your first example
You can't nest two
perch:content
tags inside each other, and I can't see why that would be needed.I needed the ids to be numbered sequentially. There are several perch:if exists lines in my template. But, as I suspected, two perch:content tags can't be nested so I'll find another way without using a repeater. Thanks
Why do the Perch IDs need to be numbered? Surely it's only the IDs for the HTML tags themselves that matter here.
Well it would be if I wasn't constrained by a particular piece of code (it a carousel of, in this case, images) which needs triggers (one for each image) to be declared before the code for the images.
So I had a scheme where I would declare six trigger instances (I'm only permitting a maximum of six images in the repeater) and then use a perch:if statement to exclude any triggers that wouldn't be needed. That all works fine but I need to identify each image with a unique id to match the id in the triggers. If, on the other hand, I could predict what the ids would be I might be able to use that in the trigger code. ... to wordy I'm sorry.
That's fine - none of that requires setting the field IDs in your Perch tags dynamically. You just need to set the
id
attributes on your HTML tags. You can useperch_item_index
for that.If you show us the code you're trying to replicate we might be able to help better.
This is the code I am using. It works but I would prefer to use a perch:repeater if I can for the panel content divs. The li trigger links have to be together and before the panel content divs and, to work, they need to have the dame ids.
I think you need to use the repeater twice: