Forum

Thread tagged as: Question

Re-use a special ID value in the same template

Does anyone know if it is possible to generate a unique ID with the perch_item_index or _id function and the re-use the generated ID in the same template? The comments in the following template show what I mean…

<section class="<!-- Generate a unique ID here -->">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <h3></h3>
            </div>
                  <perch:repeater id="Fotos" label="Fotos">
                  <div class="">
                      <a class="" href="#" data-lightbox="<!-- Re-use the generated ID here -->" data-title="#" >
                      <img class="" src="#" alt="" /></a>
                  </div>
                  </perch:repeater>
        </div>
    </div>
</section>
Edwin Venhorst

Edwin Venhorst 0 points

  • 5 years ago
<section class="<perch:content id="_id" />">

<a class="" href="#" data-lightbox="<perch:content id="_id" />" data-title="#" >

Thanks Robert, I've tried this method but the second time <perch:content id="_id" /> is used, it generates no output.

Drew McLellan

Drew McLellan 2638 points
Perch Support

That's because you're in a repeater. You need to bring the parent IDs into scope.

<perch:repeater id="Fotos" label="Fotos" scope-parent="true">
     <div class="">
         <a class="" href="#" data-lightbox="<perch:content id="parent._id" />" data-title="#" >
         <img class="" src="#" alt="" /></a>
     </div>
</perch:repeater>

I missed the repeater tag, sorry. Drew's answer will have you working. :)

Great, that does the trick. Thanks Drew an Robert! I'm loving Perch and I'm more and more getting the hang of it, but sometimes all of the options are a bit overwhelming. It's good to have this forum!