id

The id template attribute is a unique identifier for the content field. It is a required attribute. Use letters, numbers and underscores only for an id.

<perch:content id="main_heading" type="text" label="Main heading">

Re-using an ID in the template

The id identifies the content uniquely within the template. Therefore if you want to use the same content in multiple places in your template, you can re-use the id. The user adding content would only enter the content once despite in the output the content being displayed in more than one place.

An example where you might want to do this is with an email address. You want the user to enter the email address once in the edit form, but display it on the page and also as the mailto of a link. The template for this would be as follows.

You can email us at:
<a href="mailto:<perch:content id="email" type="text" label="Email address">">
    <perch:content id="email" type="text">
</a>

When an ID is reused, the options for editing are taken from the first instance of the tag in the template. Make sure any attributes that affect the editing experience are added to the first instance of the tag.

Special Values

Normally, when creating a Perch template tag, you choose the string to use for the ID, however there are a few special values you can use instead. Using one of these special values will cause Perch to output content for you as described below.

When using a special ID value also set that field to a type of hidden as the values of these fields is generated by Perch you don’t need them to display in the edit form.

The below Perch Template Tag, if used in a multiple-item region will output an index – 1 for the first item, 2 for the second and so on.

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

Special ID Values

Value Description
perch_item_index The number of the item within a multiple-item region. Outputs 1 for the first item, 2 for the second and so on.
_id The unique ID of that item of content within the region. This does not change throughout the life of the content.
perch_item_odd Outputs odd for odd-numbered items with a multiple-item region, and nothing for even items.
perch_item_count The total number of items in the region
perch_item_first Has a value for the first item only, so can be used in a perch:if, for example.
perch_item_last Has a value for the last item only, so can be used in a perch:if, for example.
_page The page path this content has been pulled from.
perch_page_path The path to the current page as Perch sees it (only useful in runtime-processed templates like forms or with perch_content_custom)
perch_item_zero_index The same as perch_item_index, but starts counting from zero.
perch_item_rev_index A count of the remaining items left, including the current item.
perch_item_rev_zero_index A count of the remaining items left.