Home Forums Add-ons Flexible Content Field Unique ID, count flexible field?


Unique ID, count flexible field?

  • Hi all,

    Any idea if the flexible content comes with unique id? I have a few flexible content and I’m also using jquery to target the class to do some jquery stuffs.

    for example, one flexible field of mine is meant to be a slider. I need to have a unique id of each generated flexible field to be able to target the slider. Otherwise if let say a user generated 2 flexible field of sliders, Slider A’s control will also trigger Slider B

    Currently I set the flexible fields to also include a compulsary field and use that as my unique ID but I’m just wondering is there such function?

  • Flexible content itself does not contain a unique ID. However, you can easily append one when outputting the flexible content. For example, if outputting your slider wrap it in a container such as:

    <div id="slider-container-<?php echo $counter++; ?>" class="slider-wrapper">
    Container content...

    Define $counter before your loop and set it to 1 or 0.

    If you’re using jQuery you can also set the context for the selector so it does not apply it document-wide:

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Unique ID, count flexible field?’ is closed to new replies.