|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Bluepink Smarty n00b
Joined: 06 Nov 2013 Posts: 3
|
Posted: Wed Nov 06, 2013 7:04 pm Post subject: Hide field if define is empty |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Nov 07, 2013 1:10 am Post subject: |
|
|
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 |
|
Bluepink Smarty n00b
Joined: 06 Nov 2013 Posts: 3
|
Posted: Thu Nov 07, 2013 1:51 am Post subject: |
|
|
Thank you so much, it worked almost perfectly. there was an extra "=" that once removed it worked perfect.
Chris |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Nov 07, 2013 1:56 am Post subject: |
|
|
I just made another test
Code: | {if $smarty.const.SHOW_3} |
would do it also |
|
Back to top |
|
Bluepink Smarty n00b
Joined: 06 Nov 2013 Posts: 3
|
Posted: Thu Nov 07, 2013 2:54 am Post subject: |
|
|
That's even better Less code has to be better
Thank you, I really appreciate it
Chris |
|
Back to top |
|
|
|
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
|