ContentBlocks content index

Just purchased ContentBlocks and getting my head around the whole thing. So far, very happy and impressed.

When a individual ContentBlock is placed onto a page does it have a unique index number (0 or 1 being the first block on the page) and is this accessible to be used as a tag.The reason this would be useful is to be able to create individual css overrides for various content blocks on different page.
Hope this makes sense.

1 Like

Hi @glynszasz ,

I like your suggestion, it can be nice to have access to a unique identifier for each layout/field in a page.

In the Fields like Gallery, Repeater you have access to the [[+idx]] and [[+total]] placeholder that allow you to “have” the iteration id and the total.
Depending on each Field you can discover more placeholder reading the code core/components/contentblocks/elements/inputs/*.

In any case, for the use that you describe I’ll suggest you to add a new properties to your Field where :

  • you can add a id manually if you need that
  • you can add a select of n class so that your final user will select the desired behaviour for the specific fields.

I hope that my suggestion can help you :wink:

An easier way to discover what placeholders are available for specific templates is to hover over the label for the template property. (When editing the field in the component) That usually lists the placeholders in the tooltip. :wink:

[[+layout_idx]] and [[+field_idx]] placeholders are also available on all fields, as is [[+unique_idx]]. These can be useful for identifying specific blocks, but they’re not fixed so those numbers will change when the page is edited. Use settings like Samuel suggests to add specific IDs or class names that don’t change.