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

How to improve readability w/ inserting space/line break??

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


Joined: 06 Jun 2019
Posts: 29

PostPosted: Fri Nov 29, 2019 11:38 pm    Post subject: How to improve readability w/ inserting space/line break?? Reply with quote

I have some horrible code like this

Code:
    {for $i=0; $i < $level; $i++}&nbsp;{if $i == $level - 1}{if $level > 1}{for $e=0; $e < $i; $e++}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{/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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1584

PostPosted: Sun Dec 01, 2019 10:15 pm    Post subject: Reply with quote

To begin with, code like "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" 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
View user's profile Send private message
pedrotester
Smarty Rookie


Joined: 06 Jun 2019
Posts: 29

PostPosted: Tue Dec 03, 2019 12:05 am    Post subject: Reply with quote

AnrDaemon wrote:
To begin with, code like "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" 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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1584

PostPosted: Tue Dec 03, 2019 10:46 pm    Post subject: Re: How to improve readability w/ inserting space/line break Reply with quote

Code:
    {for $i=0; $i < $level; $i++}&nbsp;{if $i == $level - 1
        }{if $level > 1
            }{for $e=0; $e < $i; $e++}{*
                *}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{/for}{/if}{*
        *}┗{/if}{/for}
{if $level > 0}<span>▸</span>{/if}
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