Author Topic: script not working as expected  (Read 2254 times)

0 Members and 1 Guest are viewing this topic.

Offline Roessi

  • Tireless poster
  • ****
  • Posts: 107
    • View Profile
script not working as expected
« on: January 22, 2010, 09:04:25 AM »
why does this not work O.o
Code: [Select]
{.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

Code: [Select]
{.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
« Last Edit: January 22, 2010, 09:16:07 AM by Roessi »

Offline rejetto

  • Administrator
  • Tireless poster
  • *
  • Posts: 12953
    • View Profile
script not working as expected
« Reply #1 on: January 22, 2010, 10:52:09 AM »
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.
« Last Edit: January 22, 2010, 10:54:24 AM by rejetto »

Offline Roessi

  • Tireless poster
  • ****
  • Posts: 107
    • View Profile
Re: script not working as expected
« Reply #2 on: January 22, 2010, 01:23:25 PM »
Code: [Select]
{.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 : - /

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1899
    • View Profile
Re: script not working as expected
« Reply #3 on: January 22, 2010, 01:35:04 PM »
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/


Offline Roessi

  • Tireless poster
  • ****
  • Posts: 107
    • View Profile
Re: script not working as expected
« Reply #4 on: January 22, 2010, 03:38:07 PM »
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 : - $

Offline rejetto

  • Administrator
  • Tireless poster
  • *
  • Posts: 12953
    • View Profile
Re: script not working as expected
« Reply #5 on: January 24, 2010, 03:06:19 PM »
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.