rejetto forum

function arguments not passing through {.load.}

raybob · 11 · 4675

0 Members and 1 Guest are viewing this topic.

Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
I'm not sure if this was even intended to work, but it would be great if it could.

When using ^function|a|b|c , if the function is something like this {.set|function|{:{.load|test.tpl.}:}.}  and test.tpl contains $1 $2 and $3, then the a,b,c parameters are not passed through into test.tpl.  Test.tpl would be loaded with $1 $2 and $3 staying just like that and not expanding to the parameters a,b,c.

Maybe you could even make it so you could pass arguments into {.load.} directly like load|a|b|c  :)
« Last Edit: July 14, 2012, 09:19:34 PM by raybob »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
you can do it yourself by using {.replace.}

i don't know if you can still use $1 inside test.tpl
eventually you can use {1}


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
a,b,c parameters can be passed through into test.tpl. your problem is  {.set|function|{:{.load|test.tpl.}:}.}

you have to macroquote all the text inside test.tpl
{: at the begin of file ,  :} at the end


and use the macro as it {.set|function|{.load|test.tpl.}.}

or {.set|function|{.dequote|{.load|test.tpl.}.}.} with the example

by example:
{:{.add to log| loading test.tpl.}
$1 $3 $2
{.add to log|$1 $3 $2.}
:}


then "load" is executed before "set" and parameters are replaced correctly

If you use a path for file with chars / or \ , the content of file is always macroquoted  by hfs


another possibility is to use the macro {.load|test.tpl|var=function.} and use {.^function|a|b|c.} 

with the last one and macroquote inside test.tpl, you have to use {.dequote|{.^function|a|b|c.}.}
 ;)

« Last Edit: July 16, 2012, 10:18:56 PM by Mars »



Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
yes working : ;)

udapted previous post


{.set|raybob|{.dequote|{.load|test.tpl.}.}.}
used with {.^raybob|a|b|c.}

{.load|test.tpl|var=raybob.} used with {.dequote|{.^raybob|a|b|c.}.}  

{.dequote.} is only necessary with quoted text in file or path file with "/" or "\" chars

remember that there is a section called [special:begin] where it is possible to place the initialization of variables

[special:begin]
{.load|test.tpl|var=raybob.}


[box server info]
   <fieldset id='serverinfo'>
      <legend><img src="/~img0"> {.!Server information.}</legend>
      <a href="http://www.rejetto.com/hfs/">HttpFileServer %version%</a>
      <br />{.!Server time.}: %timestamp%
      <br />{.!Server uptime.}: %uptime%
      <br />{.^raybob|welcome|HFS|to.}
   </fieldset>


test.tpl
{.add to log|loading test.tpl.}
$1 $3 $2
{.add to log|$1 $3 $2.}
{.add to log|End of loading.}
« Last Edit: July 16, 2012, 11:04:29 PM by Mars »


Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
Nice!  Although in my case test.tpl is a rather large script that I don't want to have immediately loaded into memory for every request (my function is in HFS events).

My current solution is to keep the function quoted but do something like this:

Code: [Select]
{.set|function|{:{.set|a|$1.}{.set|b|$2.}{.set|c|$3.}{.load|test.tpl.}

and replacing all instances of $1 $2 and $3 in test.tpl with ^a ^b and ^c .


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
Quote
{.set|function|{:{.set|a|$1.}{.set|b|$2.}{.set|c|$3.}{.load|test.tpl.}

{.load|test.tpl.} must be placed outside the quote, whether you liked the contents of the file is included in "function", the quotes are there to prevent that the code is interpreted

{.set|function| {: {.set|a|$1.}{.set|b|$2.}{.set|c|$3.} :} {.load|test.tpl.} .}

if you plan to use  {.^a.} {.^b.} {.^c.} or combinations of them  in test.tpl , it is easier to replace them with $1,$2, ... directly

it would be easier to show us that will contain the file test.tpl order to determine the best solution

a question to me: why your position is it placed in the events? 
Quote
(my function is in HFS events)


Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
I have a 'functions.tpl' that is loaded in hfs.events under [request] .  These functions are used globally in many places to make writing code easier so hfs.events most the most sense.

The reason that the entire function must be quoted is because I don't want it to be interpreted until it's called on.

Everything works totally fine as it's written.  The function refers to account-create.tpl, and once place it's used is ajax.submission.tpl.  

The submission script is used in 2 places, plus I have a template of over 400KB, so the fewer places I have to put this the easier it is to maintain.  Hence why I used it as a function.
« Last Edit: July 17, 2012, 04:13:32 PM by raybob »


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
instert inside your template hfs.tpl

Code: [Select]
[account-create|private]
{.load|account-create.tpl.}

[code][account-delete|private]
{.load|account-delete.tpl.}

and make changes in functions.tpl with

Code: [Select]
{.set|account-create|{:{.set|account-create-param1|$1.}{.set|account-create-param2|$2.}{.set|account-create-param3|$3.}[color=blue]{.$account-create.}[/color]:}.}
{.set|account-delete|{:{.set|account-delete-param1|$1.}{.set|account-delete-param2|$2.}{.set|account-delete-param3|$3.}[color=blue]{.$account-delete.}[/color]:}.}

then report if this work[/code]


Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
I can imagine that would work fine (I know for a fact that variables carry over into sections, I've done it), but what would it accomplish, having a section instead of {.load.} ?  My code works as I posted above.


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
Sorry, I thought there was still a worry, forget my last post ;)