rejetto forum
Software => HFS ~ HTTP File Server => Programmers corner => Topic started by: Roessi on January 12, 2010, 02:29:58 PM
-
this is for everyone this is useful for :)
{.set|doforlist|
{:
{.set|#seperator|{.switch|{.length|$3.}||0|;|$3.}.}
{.set|#list|$1{.^#seperator.}.}
{.set|#entries|{.count substring|{.^#seperator.}|{.^#list.}.}.}
{.for|ii|1|{.^#entries.}|
{:
{.set|#curitem|{.substring||{.^#seperator.}|{.^#list.}.}.}
{.set|#list|{.replace|{.^#curitem.}{.^#seperator.}||{.^#list.}.}.}
{.set|domacro|{.replace|%cur%|{.^#curitem.}|$2.}.}
{.^domacro.}
:}
.}
:}
.}
u can use it for example to show an admin page in an template with html for each user or sth. like this
{.^doforlist| list |{: command :}| optional: seperator .}
it executes the commad in parameter so many times like items exist in the list :) use %cur% for the current item f.e. :
{.^doforlist|{.get|accounts.}|{:%cur%:{.get account|%cur%|member of.}:}.}
would return every user and and the group hes member of
just thought it might be useful for someone :)
-
my contribution:
with the way you use to remove the current item from the list, a list like this
a;b;ba;a;c
would be treated like it was this
a;b;c
that's bad.
by using {.cut.} you solve this problem, and it's even faster.
i also used {.dequote.} to get the $2 executed, instead of using variable domacro.
i added {.trim.} to avoid adding extra spaces.
{.set|#doforlist|{:{.trim|
{.set|#seperator|{.switch|{.length|$3.}||0|;|$3.}.}
{.set|#list|$1{.^#seperator.}.}
{.set|#entries|{.count substring|{.^#seperator.}|{.^#list.}.}.}
{.while|#list|{:{.trim|
{.set|#curitem|{.substring||{.^#seperator.}|{.^#list.}.}.}
{.cut|var=#list|from={.add|2|{.length|var=#curitem.}.}|size=.}
.}{.dequote|{.replace|%cur%|{.^#curitem.}|$2.}.}:}.}
.}:}.}
EXAMPLE
{.^#doforlist|{.get|accounts.}|{:%cur%:{.get account|%cur%|member of.}
:}.}
i hope you enjoy this changes
-
1000 thx :) works perfectly :)
my honor to you for caring bout every single persons problems ;)
this is really nice of you ;)