• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Variable via Template Link

S

Syndol

Guest
#1
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.
 

SheepCow

Well-known member
#2
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
 

Marc

Well-known member
#4
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
 

Marc

Well-known member
#6
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
 

SheepCow

Well-known member
#7
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
 
S

Syndol

Guest
#8
SheepCow - thank you for taking the time to provide the answer/solution. It is really appreciated.
 

Marc

Well-known member
#9
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: