Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

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

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
pedrotester
Smarty Regular


Joined: 06 Jun 2019
Posts: 40

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: 1785

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 Regular


Joined: 06 Jun 2019
Posts: 40

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: 1785

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
pedrotester
Smarty Regular


Joined: 06 Jun 2019
Posts: 40

PostPosted: Tue Dec 17, 2019 9:19 pm    Post subject: Re: How to improve readability w/ inserting space/line break Reply with quote

Alright, that works, it's still ugly but maybe less, thank you Very Happy

(in jinja python framework, we can easily remove spaces and linebreaks with a parameter, might be interesting to have in smarty)
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    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