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

Variable via Template Link

Discussion in 'XenForo Development Discussions' started by Syndol, Jun 4, 2011.

  1. Syndol

    Syndol Guest

    I am trying to pass a variable to a PHP file via a template link:
    <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
    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.
  2. SheepCow

    SheepCow Well-Known Member

    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 likes this.
  3. SheepCow

    SheepCow Well-Known Member

    You may want something like:

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

    Then you can filterSingle on "name" to get Bob back.
    Marc likes this.
  4. Marc

    Marc Well-Known Member

    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
  5. SheepCow

    SheepCow Well-Known Member

    Try something like:

    {xen:link 'MyApp/MyPage', '', 'name={$name}'}
    Marc likes this.
  6. Marc

    Marc Well-Known Member

    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:-


    What I want to know how people achieve is as follows

  7. SheepCow

    SheepCow Well-Known Member

    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
    Marc likes this.
  8. Syndol

    Syndol Guest

    SheepCow - thank you for taking the time to provide the answer/solution. It is really appreciated.
  9. Marc

    Marc Well-Known Member

    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:

Share This Page