|
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:31 pm Post subject: How to repeat a character X times where X is a variable |
|
|
In a foreach loop, I put a:
Code: | {for $i=0; $i < $level; $i++} {if $i == $level - 1}{if $level > 1}{for $e=0; $e < $i; $e++} {/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++} {if $i == $level - 1}{if $level > 1}{repeater( " ", 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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Dec 01, 2019 10:19 pm Post subject: |
|
|
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 |
|
pedrotester Smarty Regular
Joined: 06 Jun 2019 Posts: 40
|
Posted: Tue Dec 03, 2019 12:02 am Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Dec 03, 2019 10:42 pm Post subject: |
|
|
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 |
|
pedrotester Smarty Regular
Joined: 06 Jun 2019 Posts: 40
|
Posted: Mon Dec 16, 2019 5:53 pm Post subject: |
|
|
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 |
|
|
|
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
|