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

How to repeat a character X times where X is a variable

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

PostPosted: Fri Nov 29, 2019 11:31 pm    Post subject: How to repeat a character X times where X is a variable Reply with quote

In a foreach loop, I put a:

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}


My goal is to put multiple spaces (5).

There is also this method with the function "repeater" (from codeigniter)
Code:
{for $i=0; $i < $level; $i++}&nbsp;{if $i == $level - 1}{if $level > 1}{repeater( "&nbsp;", 5 * ($level - 1) )}{/if}┗{/if}{/for}



I don't know which one is better, and it might not even be suited to post here (but if I ask on php boards they might tell me it's not suited either)


How would you proceed with smarty?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1615

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

Define "better" ?

As I said earlier in another thread, I wouldn't do anything like that to begin with. Formatting with explicit spaces is a last resort option. And even then, it's ideographic spaces (U+3000), not NBSP's, for me.
Back to top
View user's profile Send private message
pedrotester
Smarty Rookie


Joined: 06 Jun 2019
Posts: 33

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

for curiosity I replaced nbsp by U+3000 and it didn't work at all (it just displayed "U+3000" and only once instead of 5 times)

I don't know how to do better, btw it's not that important it's in an admin panel page, but it's just really noobish

Do you mean you would do it with CSS ? but how would I do that based on the loop? I would put inline CSS and multiply the value by the {$level} variable?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1615

PostPosted: Tue Dec 03, 2019 10:42 pm    Post subject: Reply with quote

If you want to display tree-like structure, it's better to use JS-based solution, like PEAR HtmlTreeMenu.
If you desperately want to code it yourself, nested (un)ordered lists with appropriate CSS are the way to go.

Regarding your implicit "how to refer to and use the UNICODE code points" question, I would strongly suggest http://fileformat.info/
Back to top
View user's profile Send private message
pedrotester
Smarty Rookie


Joined: 06 Jun 2019
Posts: 33

PostPosted: Mon Dec 16, 2019 5:53 pm    Post subject: Reply with quote

AnrDaemon wrote:
If you want to display tree-like structure, it's better to use JS-based solution, like PEAR HtmlTreeMenu.
If you desperately want to code it yourself, nested (un)ordered lists with appropriate CSS are the way to go.

Regarding your implicit "how to refer to and use the UNICODE code points" question, I would strongly suggest http://fileformat.info/


hmm true for nested lists, I could have done this, with some nth-children on the css, if I need I'll retry with that (but for now it works fine, it's just ugly in code)
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