Variable via Template Link

  • Thread starter Thread starter Syndol
  • Start date Start date
S

Syndol

Guest
I am trying to pass a variable to a PHP file via a template link:
HTML:
<a href="{xen:link phpfile, $post}" class="OverlayTrigger">myLink</a>

However, the link always shows 'index.php?phpfile/user_id/
and once inside the PHP file, the
PHP:
->filterSingle('variable', XenForo_Input::UINT);
->filterSingle('variable', XenForo_Input::ARRAY_SIMPLE);
does not work.

There is no doubt a simple and elegant XenForo way of passing and retrieving variables from template to file - so what am I missing here o_O
Thanks in advance.
 
The xen:link template helper passes the parameters to the link builder for the "phpfile" route. That then builds the URL for it.

E.g. the "posts" route simply takes the post_id out of the $post array and sticks it on the end. All that actually goes in the URL is the ID, the controller at the other end has to lookup the ID again
 
You may want something like:

{xen:link phpfile, '', 'name=Bob'}

Then you can filterSingle on "name" to get Bob back.
 
You may want something like:

{xen:link phpfile, '', 'name=Bob'}

Then you can filterSingle on "name" to get Bob back.

Using xen:link, however had problems with the parameter.

<a href="{xen:link MyApp/MyPage,' ','user={$userArray.userid}'">{$userArray.username}</a>

also tried

<a href="{xen:link MyApp/MyPage,' ','user=$userArray.userid'">{$userArray.username}</a>

Both give me template errors
 
Try something like:

{xen:link 'MyApp/MyPage', '', 'name={$name}'}

Ah yeah .. if I make sure all the quotes and braces were there that would help LOL

OK, now that answers that question LOL ... however still leaves my original question above

I currently have, for example a mythical profile for a person called dave:-

http://www.mysite.com/myapp/profiles/Profile?profile=2

What I want to know how people achieve is as follows

http://www.mysite.com/myapp/profiles/Dave.2
 
Have a look at the Thread route code (something like XenForo_Route_Prefix_Thread), the build link function creates links with the titles in them and the route match pulls out the thread id and title
 
SheepCow - thank you for taking the time to provide the answer/solution. It is really appreciated.
 
Have a look at the Thread route code (something like XenForo_Route_Prefix_Thread), the build link function creates links with the titles in them and the route match pulls out the thread id and title

Cheers m8 :) And ya know I just realised I hadnt asked that question above, it was in another topic LMAO. How much had I had to drink yesterday? LOL :eek:
 
Top Bottom