Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
I am trying to detect the k_page_title to display specific text in an H2 block. Not matter what I do it ignores the first if statement and still displays the <cms:show k_page_title /> in the first if statement and ignores the following if's. Am I missing something obvious here?

Code: Select all
<h2>
                     <cms:if k_page_title!='Eagles' || k_page_title!='Horses' || k_page_title!='Fountains'>
                        <cms:show k_page_title />
                        <cms:else />
                        <cms:if k_page_title='Eagles'>Eagle
                           <cms:else />
                           <cms:if k_page_title='Horses'>Horse
                              <cms:else />
                              <cms:if k_page_title='Fountains'>Fountain
                              </cms:if>
                           </cms:if>
                        </cms:if>
                     </cms:if>
                     Bronze Sculptures</h2>

tonjaggart wrote: Am I missing something obvious here?

Yes. ;) You should connect the initial if conditions with &&.

Think about the statement in plain English. "if it's not eagles do something OR if it's not horses do something OR if it's not fountains do something." That condition is always true.

You want "if it's not eagles AND it's not horses AND it's not fountains do something."
I clearly had these backwards *facepalm. Thanks so much Tim!
An alternative would be to test each of the specific conditions first then if none applies, use the default. But if the other way makes more sense to you, it's no big deal.
Code: Select all
<h2>
    <cms:if k_page_title='Eagles'>Eagle <cms:else />
        <cms:if k_page_title='Horses'>Horse <cms:else />
            <cms:if k_page_title='Fountains'>Fountain <cms:else />
                <cms:show k_page_title /> 
            </cms:if>            
        </cms:if>
    </cms:if>
Bronze Sculptures</h2>
This is how I would prefer to do it. It is much cleaner.
I clearly had these backwards *facepalm.
That's perfectly fine, Ton :) That's something no programmer can claim to have never been confused about.
6 posts Page 1 of 1