Support Forums

Smarty "or" variable?

This is a discussion on Smarty "or" variable? within the Technical Support forums, part of the Technical Support Forums category; I'm trying to do the <title> modification, but I'm unsure how to do "or" statements with smarty tags. Like this ...


Go Back   68 Classifieds Forums > Technical Support Forums > Technical Support

This topic is resolved.

If you have a similar issue that this thread does not address, open a new related support topic.

 
Thread Tools Display Modes
Old 03-03-2008, 02:44 AM   #1
Senior Member
 
cwp's Avatar
 
Join Date: Jun 2007
Posts: 296
Rep Power: 23
cwp is a jewel in the rough
Default Smarty "or" variable?

I'm trying to do the <title> modification, but I'm unsure how to do "or" statements with smarty tags.

Like this

Code:
{if $body=='viewlisting2.tpl'}
<title>my custom title</title>
{if $body=='categories/browse.tpl'}
<title>my custom title</title>
{/if}
{else}
<title>{$sitetitle}</title>
{/if}
Code:
{if $body=='viewlisting2.tpl'}
<title>my custom title</title>
{/if}
{if $body=='categories/browse.tpl'}
<title>my custom title</title>
{else}
<title>{$sitetitle}</title>
{/if}

I've tried many different methods but none of them work just right. The 2nd method works, but shows the original sitetitle with both variables.

I checked out the official smarty site and couldn't find anything on "or" variables. I know this can be done with PHP, just wanted to make sure this can't be done with just smarty first.
__________________
Version 4.0.3 Developer
cwp is offline  
Old 03-03-2008, 08:51 AM   #2
curmudgeon
 
Join Date: Mar 2006
Posts: 5,366
Rep Power: 135
Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light
Default

Quote:
Originally Posted by cwp
I'm trying to do the <title> modification, but I'm unsure how to do "or" statements with smarty tags.

Like this

Code:
{if $body=='viewlisting2.tpl'}
<title>my custom title</title>
{/if}
{if $body=='categories/browse.tpl'}
<title>my custom title</title>
{else}
<title>{$sitetitle}</title>
{/if}

I've tried many different methods but none of them work just right. The 2nd method works, but shows the original sitetitle with both variables.

I checked out the official smarty site and couldn't find anything on "or" variables. I know this can be done with PHP, just wanted to make sure this can't be done with just smarty first.
The easiest thing I have found when having trouble wrapping your mind around something is to just write it out in simple english. Then convert it to code later.

In your second example you are saying.....


if the body variable equals viewlisting2.tpl then the title should be my custom title.

and immediatly after it you say.....

if the body variable equals categories/browse.tpl then the title should be my custom title AND if its not it should just be the site title.

By the time it does the second evaluation its already done the first and thats why your getting the title twice.

Things within a single {if} {/if} get evaluated together and only the correct outcome is displayed. In your second example you have 2 different {if} {/if} sections but only the second has an {else} in it. This means that in total you are evaluating the body 2 times and displaying results 2 times. You need to have all the evaluations in a single group OR have indivudual evaluations that only display if the evaluation is true so that you wont have duplicate output.

Something like this would evaluate the the body variable and compare it to 2 options, if it doesnt matche either it will use the last one after the else....

Code:
{if $body=='viewlisting2.tpl'}
<title>my custom title</title>
{elseif $body=='categories/browse.tpl'}
<title>my custom title</title>
{else}
<title>{$sitetitle}</title>
{/if}
__________________
Larry

Knowledge learned is more valuable than knowledge given.
Lhotch is offline  
Old 03-03-2008, 02:44 PM   #3
Senior Member
 
cwp's Avatar
 
Join Date: Jun 2007
Posts: 296
Rep Power: 23
cwp is a jewel in the rough
Default

{else if

is exactly what I was looking for.. I should have asked it out in a simpler language!

Thanks again.
__________________
Version 4.0.3 Developer
cwp is offline  
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Image URL and Smarty Templates Kateedyd Templates, HTML, CSS, and Design Help 21 02-02-2008 02:06 PM
Smarty Templates and You. Posted BY Lhotch Eric Barnes Templates, HTML, CSS, and Design Help 13 10-02-2007 08:06 AM


All times are GMT -4. The time now is 11:13 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2011, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0