Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

whats the best practice or rule to write the if condition

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
vbmali9191
Smarty n00b


Joined: 30 Jan 2018
Posts: 1

PostPosted: Tue Jan 30, 2018 5:37 am    Post subject: whats the best practice or rule to write the if condition Reply with quote

When I am writing my if block open and close in one line then it creates a problem while printing the variable, but not when I am using like this:

{if isset($title)}
{$title}
{/if}


Problem with:

{if isset($title)}{$title}{/if}

if I use the code in single line the variable prints unnecessary spaces at the end of string, I have tried by using strip and trim but no use.

What's the reason behind this problem?
Back to top
View user's profile Send private message
bsmither
Smarty Pro


Joined: 20 Dec 2011
Posts: 194
Location: West Coast

PostPosted: Tue Jan 30, 2018 5:47 am    Post subject: Reply with quote

The problem is that some code in Smarty does not manage line endings after certain tags.

See:
https://www.smarty.net/forums/viewtopic.php?t=26878
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1384

PostPosted: Tue Jan 30, 2018 4:29 pm    Post subject: Reply with quote

It may be not a space after variable, but a space after {/if}.
Back to top
View user's profile Send private message
crownclown67
Smarty Rookie


Joined: 03 May 2018
Posts: 12

PostPosted: Wed Aug 15, 2018 7:02 am    Post subject: Reply with quote

My question is:
Why You use {if isset($title)}{$title}{/if}

but not only this {$title} ?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1384

PostPosted: Wed Aug 15, 2018 11:43 am    Post subject: Reply with quote

{$title|default:''}

would be more appropriate to the present cause.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    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