Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Hide field if define is empty

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Bluepink
Smarty n00b


Joined: 06 Nov 2013
Posts: 3

PostPosted: Wed Nov 06, 2013 7:04 pm    Post subject: Hide field if define is empty Reply with quote

Hi Everyone, This is the first time Ive worked with smarty so please go easy on me.

I have the drop down list below, with each option being populated from my language file with the "define" field, also below.


Code:
<select name="showname" class="required" style="width: 155px;">
                  <option value="{$smarty.const.SHOW_1|htmlentities:3:'UTF-8'}"{if isset($movies) && $movies->showname} selected{/if}>{$smarty.const.SHOW_1|htmlentities:3:'UTF-8'}</option>
                  <option value="{$smarty.const.SHOW_2|htmlentities:3:'UTF-8'}"{if isset($movies) && $movies->showname} selected{/if}>{$smarty.const.SHOW_2|htmlentities:3:'UTF-8'}</option>
                  ---59 other options--
</select>


Code:
/**
 * Shows
 */
define("SHOW_1",                           "show blah blah");
define("SHOW_2",                           "show blah blah2");
define("SHOW_3",                           "");


now this works perfectly when there is a defined show, like SHOW_1 & SHOW_2, but when it comes to SHOW_3, the value is blank as i imagined it would be, but i was hoping
the blank fields wouldn't be visible on the website, instead hidden until a value was inserted into the SHOW_3 define. Unfortunately this isn't the case, so, my question is, can i hide the field if there is no value for "SHOW_3"?

I apologize if that was really confusing, if it was then i will try to explain again.

Any help would be fantastic as Ive been trying to figure this out for the last 5/6 hours.

Chris.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Nov 07, 2013 1:10 am    Post subject: Reply with quote

To test if a constant is defined does require a special if condition.

Code:
{if null !== $smarty.const.SHOW_3}<option value="{$smarty.const.SHOW_3|htmlentities:3:'UTF-8'}"{if isset($movies) && $movies->showname} selected{/if}>{$smarty.const.SHOW_3|htmlentities:3:'UTF-8'}</option>{/if}
Back to top
View user's profile Send private message
Bluepink
Smarty n00b


Joined: 06 Nov 2013
Posts: 3

PostPosted: Thu Nov 07, 2013 1:51 am    Post subject: Reply with quote

Thank you so much, it worked almost perfectly. there was an extra "=" that once removed it worked perfect.

Chris
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Nov 07, 2013 1:56 am    Post subject: Reply with quote

I just made another test

Code:
{if $smarty.const.SHOW_3}


would do it also
Back to top
View user's profile Send private message
Bluepink
Smarty n00b


Joined: 06 Nov 2013
Posts: 3

PostPosted: Thu Nov 07, 2013 2:54 am    Post subject: Reply with quote

That's even better Very Happy Less code has to be better Very Happy

Thank you, I really appreciate it Smile

Chris
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP