|
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 |
Game Over! Smarty Rookie
Joined: 01 May 2019 Posts: 10
|
Posted: Wed Sep 04, 2019 11:38 am Post subject: Standard if statement |
|
|
Hello guys.
I just wanna know is there any difference between these two? If there is , so which one is better ? which one has more performance ?
Code: |
<div class="container">
<div class="row">
<h1>Test</1>
{if $Gender eq "male" }
<p>Hello Mr</p>
{else}
<p>Hello Mrs</p>
{/if}
</div>
</div>
|
or
Code: |
{if $Gender eq "male" }
<div class="container">
<div class="row">
<h1>Test</1>
<p>Hello Mr</p>
</div>
</div>
{else}
<div class="container">
<div class="row">
<h1>Test</1>
<p>Hello Mrs</p>
</div>
</div>
{/if}
|
|
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Wed Sep 04, 2019 8:52 pm Post subject: |
|
|
Two <div> blocks are going to be sent out anyway. The first example is more normalized than the second, but having:
Code: | {if $Gender eq "male"}Mr{else}Mrs{/if} | is even more normalized. That is, every bit of common code is outside anything that could change, and appears once -- easiest to make changes. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Sep 08, 2019 5:15 pm Post subject: |
|
|
Only one block will be sent to the user, but which approach is better is a nontrivial question.
In this specific case, the first one I would prefer.
But YMMV. |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Sun Sep 08, 2019 7:13 pm Post subject: |
|
|
"Only one block will be sent"
The 'container' and the nested 'row'. Slapdash notes. |
|
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
|