How do I pull the item id into the content?

  • I have a repeater in a repeating region.

    I need each repeater to have a unique id. i.e. the repeating region item id.

    Using perch_item_index returns a unique id within the region but the repeater resets this, and as all the regions appear on the page they are not unique.


    Region = <perch:content id="perch_item_index" type="hidden" />

    <perch:repeater id="topics">

    Topic = <perch:content id="perch_item_index" type="hidden" />

    </perch:repeater>


    For 2 items in the region this produces;

    Region = 1

    Topic = 1

    Topic = 2

    Region = 2

    Topic = 1

    Topic = 2


    I want something like;

    Region = 1

    Topic = 1_1

    Topic = 1_2

    Region = 2

    Topic = 2_1

    Topic = 2_2


    So is there a way to pull in the itm id? As in the URL /perch/core/apps/content/edit/?id=35&itm=31

  • drewm

    Approved the thread.
  • Hi,


    perch_item_index does not give you a unique ID. It gives you the number of the item in a list in whatever context it is (number of item in a region, number of item in a repeater, etc). So I would prepend the region unique ID to avoid possible clashes.


    You can use _id which is the unique ID of the region. And you can use the scope-parent attribute on the repeater tag to make the content from outside the repeater available inside it:


    HTML
    1. RegionID_RegionItemNumber: <perch:content id="_id" type="hidden">_<perch:content id="perch_item_index" type="hidden">
    2. <perch:repeater id="my_repeater" scope-parent>
    3. RegionID_RegionItemNumber_RepeaterItemNumber: <perch:content id="parent._id" type="hidden">_<perch:content id="parent.perch_item_index" type="hidden">_<perch:content id="perch_item_index" type="hidden">
    4. </perch:repeater>