rejetto forum
Software => HFS ~ HTTP File Server => Programmers corner => Topic started by: Roessi on January 22, 2010, 09:04:25 AM
-
why does this not work O.o
{.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.}.}:}.}
.}:}.}
the function ^^ again sth i found u could use it for
{.load|{.^#doforlist|iPhone;MSIE|{:{.if|{.>|{.count substring|%cur%|{.header|User-Agent.}.}|0.}|%cur%.tpl|Default.tpl.}:}.}.}
it just displays the template code ... and all the special: sections are empty
-
1. you are looping (twice) over the {.if.}
getting as a result Default.tplDefault.tpl
then you pass this to {.load.} but it's not an existing file.
the logic is wrong.
this is a possible way to correct
fn = default.tpl
for iphone,MSIE
if %cur% in user-agent
fn = %cur%.tpl
load(fn)
when something goes wrong with scripts, you should: debug > enable macros.log
and read what's happening
2. since {.count substring.} returns a value that's a number, zero or positive, you can avoid using {.>.} because zero will be considered as "false" and the positive as "true".
3. i think you can use {.pos.} instead of {.count substring.} because you are not interested in how many times it appears, but if it appears at all.
-
{.load|/template/functions/doforlist.txt|var=#doforlist.}
{.^#doforlist|iPhone;MSIE|
{.if| {.pos|%cur%|{.header|User-Agent.}.} | {.set|loadtpl|%cur%.tpl.} | {.set|loadtpl|Default.tpl.} .}
.}
{.load|{.^loadtpl.}|var=tpl.}
{.^tpl.}
thx the looping was correct if the list contained more then 1 item but... i changed it to upper code and it displays only the text of the tpl file and doesnt use it : - /
-
Here is the web page which deals with the probleme in mode php, it is enough to adapt it with macro to put on it
http://detectmobilebrowsers.mobi/ (http://detectmobilebrowsers.mobi/)
-
but the detecting works and it loads the complete code from the template file it shoulkd load but the browser displays only text and no html : - $
-
thx the looping was correct if the list contained more then 1 item but... i changed it to upper code and it displays only the text of the tpl file and doesnt use it : - /
1. you forgot to {:quote:} the actions of the {.if.}
you can avoid this only when the actions have no side effects.
that's not the case.
2. you cannot load a template by using {.load.}
load doesn't load a template, loads a simple text.
the very difference is that [sections] are not treated.
i will work on a {.load tpl.} in the future. that's not hard, but it takes some time because it requires a cache system to be decent.