Forum for discussing general topics related to Couch.
5 posts Page 1 of 1
Hi,
I am trying to do an if statement for <cms:show main_image />.

My goal is to show another image if the main_image is empty or blank. I tried something like the following

Code: Select all
<cms:if '<cms:show main_image />' == "" >
                 '<cms:show another_image />'
              <cms:else />
                  '<cms:show main_image />'
   </cms:if>


But its not working.

Assistance would be greatly appreciated.
Hi,

Following should work -
Code: Select all
<cms:if main_image = ''>
    <cms:show another_image />
<cms:else />
    <cms:show main_image />
</cms:if>

You can place that code as the 'src' param of <img> tag so the following -
Code: Select all
<img src="" />

- would become
Code: Select all
<img src="
    <cms:if main_image = ''>
        <cms:show another_image />
    <cms:else />
        <cms:show main_image />
    </cms:if>
" />

or all in a single line -
Code: Select all
<img src="<cms:if main_image = ''><cms:show another_image /><cms:else /><cms:show main_image /></cms:if>" />

Hope this helps.
Where there is only a single 'another' image, the if-else construct can be replaced by <cms:get> with parameter default -
Code: Select all
<img src="<cms:get 'main_image' default=another_image />" />
This worked perfectly
Code: Select all
<img src="<cms:get 'main_image' default=another_image />" />

Thanks trendoman it gave me the result I wanted.
CouchCMS never ceases to amaze!
5 posts Page 1 of 1

Who is online

In total there are 9 users online :: 0 registered, 0 hidden and 9 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 9 guests