Forum for discussing general topics related to Couch.
7 posts Page 1 of 1
Good evening everyone.
I'm looking for a way to display a company address on a clonable page, based on a location chosen from the backend.
That is, I would like:
If I choose from backend: France
In the front end I have:
ACSE corporation
via heart, 32
Paris

If I choose from backend: Italy
In the front end I have:
ACSE spa
Via delle rose, 12
Milan.

I tried to set the values of the companies in the global file, then how can I recall them?

Thanks to those who can help me
Hi,

I tried to set the values of the companies in the global file,

Could you please post your current code?
Thanks KK,
my code is below.

Code: Select all
<?php require_once( 'admincms/cms.php' ); ?>

  <cms:template title='Global Setting' parent='impostazioni' executable='0'/>
 
  <cms:editable name='def_filiali' label='Elenco Filiali' desc='Inserisi le filiali' type='group' collapsed='1'/>      
   

       <cms:repeatable name='filiale' label='Filiale' stacked_layout='0' group='def_filiali'>
      
      <cms:editable name='sede_filiale'
        label="Sede di"
      desc='Inserisci sede della filiale'
       type='text'
      group='def_filiali' />
      

   <cms:editable name='dati_filiali'
        label="Dati Filiali"
      desc='Inserisci i dati delle filiali'
       type='richtext'
       toolbar='full'
      group='def_filiali' />
      
   </cms:repeatable>   
      
<?php COUCH::invoke(); ?>



Formed by only 2 fields (I felt it was more convenient)
The first is the branch office
The second containing address, telephone etc. etc.

I would like that by pointing to the branch field, I would go and fetch the data of the second corresponding field.
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
a.png (28.18 KiB) Viewed 1389 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=11105

The 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
b.png (4.95 KiB) Viewed 1389 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.
Thanks KK for the detailed explanation.
I will try to put into practice what you have indicated to me.
I hope to succeed and to give news.
Thank you
Thanks KK, your solution works great.
Thanks to your indications, I have also used the system for other functionalities.
Great Couch !!
Thanks :) I am glad it helped.
7 posts Page 1 of 1