By: Chris Fordham
Date: 2006-04-27
Time: 07:26
|
Conditional php vars
I am creating a framework that uses php vars/arrays for use in subtemplates (which are header, footer, nav etc).
In the header subtlpl I might have a line:
<meta name="keywords" content="[var.keywords]" />
However I want to make it by the logic that if the keywords var is set, it shows the line ie.
if $keywords echo <meta name="keywords" content="[var.keywords]" />
So the site has a included config files of all these kinds of vars and only adds lines if the vars are set.
How would you do that?
|
By: Skrol29
Date: 2006-04-27
Time: 09:58
|
Re: Conditional php vars
<meta name="keywords" content="[var.keywords;magnet=meta;mtype=m*]" />
|
|
By: Chris Fordham
Date: 2006-04-27
Time: 10:14
|
Re: Conditional php vars
Thanks Skrol29, your suggestion is pretty much what I was using, however if the php variable is unset, it will still return error like:
TinyButStrong Error (Array value): Can't merge [var.conf_tbs.copdyright] because sub-item 'copdyright' is not an existing key in the array. This message can be cancelled using parameter 'noerr'.
Can you do it to avoid this ie. if the person does not set the variable at all in the conf include?
|
By: Chris Fordham
Date: 2006-04-27
Time: 10:15
|
Re: Conditional php vars
Ah and by avoiding this i mean without using noerr?
|
By: Skrol29
Date: 2006-04-27
Time: 10:48
|
Re: Conditional php vars
Why don't you want "noerr" ? It's a good way.
An other issue is to add:
if (!isset($keywords)) keywords = '';
|
By: Chris Fordham
Date: 2006-04-27
Time: 11:48
|
Re: Conditional php vars
Ok ur right, i just gotta work out best how to remove the spacing if its not set just for aesthetic purposes ie. if you leave 5 header vars blank in the config, you'll have 5 blank lines...
|
|
Posting in progress.
Please wait...
|