Hello,
When using a flexible content field it’s possible for users to move the layouts/blocks around which is perfect, however if I want to target a specific/unique layout with a CSS class there doesn’t seem to be a slug for these layouts, only get_row_layout().
I can’t use the output of get_row_layout() as there could be multiple layouts of the same type on a page. I can’t append an iterative count to the get_row_layout() as the order could change.
Is there any way of specifying a unique ID for a container layout/block within a flexible content field that will remain static irrespective of sub-field changes?
I can’t find one but it’s very possible I’m missing something.
Many thanks
Hi @studio4
You can always create a text field in the layouts to store the layout id.
I hope this helps.
Hello James,
Yes I could use an additional field but there is no easy (automated) way of making this unique to the block: it would need to be manually maintained.
The identifier doesn’t need to be a slug, just some form of unique id; I’ll find a way to work around the problem but could this be added to the feature requests?
Hi @studio4
You can always use the acf/save_post hook to set the layout id field automatically. To update the flexible content, please take a look at this page: https://www.advancedcustomfields.com/resources/update_field/.
You can loop through the flexible content field and set the layout id field automatically if it’s empty.
I hope this makes sense. Thanks!