Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Hello there,

I have a dropdown in the admin side. There are three options, just like in the example in the CouchCMS tutorial.

Code: Select all
<cms:editable name="my_property_type" label="Property Type" desc="Select one from these"
  opt_values='Residential=0 | Commercial=1 | Rental=2'
  opt_selected = '2'
  type='dropdown'
/>


So the admin select Rental in the menu however when I try to show it in the html page when I use
Code: Select all
<cms:show my_property_type />


I get an int (number). Is there a way to get both with the show view? I need to get Rental and 2 number in different places on the same page. So I would like to have something like
Code: Select all
<cms:show my_property_type.label />
<cms:show my_property_type.value />


Thank you your advise.
Hello, @gratas, it is possible to remove numbers, having only titles, in configuration of your editable dropdown - but you said numbers are also needed, so that's not the option.

One friend used a JS solution to take currently selected option of dropdown in the front-end and printed the text of element somewhere else, thus covering it easily for his usecase (showing filter title in search result). Can't provide JS code for this solution.

A real fast and affordable solution is to have values stored as new variables. Almost no overhead, check this:
Residential=0 | Commercial=1 | Rental=2

Code: Select all
<cms:if my_property_type = '0' >
   <cms:set property_desc = 'Residential' scope='global' />
<cms:else_if my_property_type = '1'  />
   <cms:set property_desc = 'Commercial' scope='global' />
<cms:else_if my_property_type = '2'  />
   <cms:set property_desc = 'Rental' scope='global' />
</cms:if>

<cms:show property_desc />

Code: Select all
<cms:set property_desc = "<cms:if my_property_type = '0' >Residential<cms:else_if my_property_type = '1'  />Commercial<cms:else_if my_property_type = '2'  />Rental</cms:if>" scope='global' />

<cms:show property_desc />


Apart of that I can't provide any more elegant solution. :)

P.S. For ease of use maybe some other variant:
Code: Select all
<cms:set property_desc_0 = 'Residential' scope='global' />
<cms:set property_desc_1 = 'Commercial' scope='global' />
<cms:set property_desc_2 = 'Rental' scope='global' />

<cms:get "property_desc_<cms:show my_property_type />" />

<cms:get /> is the same as <cms:show /> and can take our dynamically constructed variable property_desc_NUM as parameter.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Thank you @ trendoman for sharing this solution!
3 posts Page 1 of 1