|
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 |
pedrotester Smarty Regular
Joined: 06 Jun 2019 Posts: 40
|
Posted: Fri Nov 29, 2019 11:38 pm Post subject: How to improve readability w/ inserting space/line break?? |
|
|
I have some horrible code like this
Code: | {for $i=0; $i < $level; $i++} {if $i == $level - 1}{if $level > 1}{for $e=0; $e < $i; $e++} {/for}{/if}┗{/if}{/for}
{if $level > 0}<span>▸</span>{/if} |
Exactly like this because if I move the {} for better readability, then it will insert unwanted space or line break
Can you show me how to make the code I've put more readable in Smarty, please?
Last edited by pedrotester on Tue Dec 03, 2019 12:05 am; edited 1 time in total |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Dec 01, 2019 10:15 pm Post subject: |
|
|
To begin with, code like " " is bad for multiple reasons.
And if you absolutely want to structure this mess, you can either split lines INSIDE Smarty tags, or use Smarty comments "{* … *}" |
|
Back to top |
|
pedrotester Smarty Regular
Joined: 06 Jun 2019 Posts: 40
|
Posted: Tue Dec 03, 2019 12:05 am Post subject: |
|
|
AnrDaemon wrote: | To begin with, code like " " is bad for multiple reasons.
And if you absolutely want to structure this mess, you can either split lines INSIDE Smarty tags, or use Smarty comments "{* … *}" |
Sorry, I don't understand :'(
Split lines inside Smarty tags? but I need to close the tags and write HTML in the tags, and that's where the problem is
And use comments? but it will just comment/disable the code
Can you show me how to make the code I've put more readable in Smarty, please? (forgot to write this the first time) |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Dec 03, 2019 10:46 pm Post subject: Re: How to improve readability w/ inserting space/line break |
|
|
Code: | {for $i=0; $i < $level; $i++} {if $i == $level - 1
}{if $level > 1
}{for $e=0; $e < $i; $e++}{*
*} {/for}{/if}{*
*}┗{/if}{/for}
{if $level > 0}<span>▸</span>{/if} |
|
|
Back to top |
|
pedrotester Smarty Regular
Joined: 06 Jun 2019 Posts: 40
|
Posted: Tue Dec 17, 2019 9:19 pm Post subject: Re: How to improve readability w/ inserting space/line break |
|
|
Alright, that works, it's still ugly but maybe less, thank you
(in jinja python framework, we can easily remove spaces and linebreaks with a parameter, might be interesting to have in smarty) |
|
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
|