by
KK » Sat Jun 11, 2022 4:56 pm
Thanks.
This use-case can be solved using 'relations' but since the list of addresses is not likely to be huge let us continue with the repeatable-regions you used. Following is how we can solve the issue -
For the sake of clarity for anyone chancing upon this thread later, I'll use this definition for the repeatable-regions -
- Code: Select all
<cms:repeatable name='offices' label='Offices'>
<cms:editable name='office_name' label="Name" type='text' />
<cms:editable name='office_address' label="Address" type='textarea' />
</cms:repeatable>
I am assuming the above is placed in a non-clonable template named 'globals.php'.
With data it could look like this -

- a.png (28.18 KiB) Viewed 3138 times
Now suppose you wish to show a dropdown listing the names of the offices above in any another template.
We can create such a dropdown by dynamically populating it with values from the global repeatable region (as first shown in
viewtopic.php?f=4&t=1671&p=2483&hilit=dynamic_params#p2483).
To do that, place a snippet (in 'couch/snippets' folder or whatever folder you have set for snippets in couch/config.php file) named 'my_list_addresses.html' and place the following content -
- Code: Select all
Please Select=-
<cms:get_field 'offices' masterpage='globals.php'>
<cms:show_repeatable k_field_name >
| <cms:show office_name />
</cms:show_repeatable>
</cms:get_field>
N.B. if you are not familiar with <cms:get_field> please take a look at
viewtopic.php?f=5&t=11105The snippet above iterates through the repeatable-region in globals.php and outputs the office-names. We can use it to populate a dropdown editable region by placing the following definition in the template where you want to offer the dropdown -
- Code: Select all
<cms:editable name="selected_office" label="Selected Office" opt_values='my_list_addresses.html' dynamic='opt_values' type='dropdown' />
You should now see a dropdown showing values from your global repeatable-region -

- b.png (4.95 KiB) Viewed 3138 times
Ok, so now the user can select an office in the backend using the dropdown.
We can use that selected office to output the full address as follows -
- Code: Select all
<h2>Office</h2>
<cms:get_field 'offices' masterpage='globals.php'>
<cms:show_repeatable k_field_name >
<cms:if office_name eq selected_office>
<h3><cms:show office_name /></h3>
<cms:nl2br><cms:show office_address /></cms:nl2br>
</cms:if>
</cms:show_repeatable>
</cms:get_field>
Hope this helps. Do let me know.