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

How do I get a Thread URL in a Template if I only have the Thread ID?

R

ragtek

Guest
#5
HTML:
<a href="{xen:link 'threads', {xen:array 'thread_id={$threadId}'}}">Link to thread</a>
It won't contain the title, but it will work and it's future proof.
i've tried:

{xen:link 'foobar/baz', {xen:array 'post_id={$post.post_id}'}}
// $post is a array containtaing post_id & title
and the generated link is only foobar/baz, but i need foobar/baz?post_id=240

do i need to set anything in the route buildlink?? (that's what i don't want to do:/
 

James

Well-known member
#6
i've tried:

{xen:link 'foobar/baz', {xen:array 'post_id={$post.post_id}'}}
// $post is a array containtaing post_id & title
and the generated link is only foobar/baz, but i need foobar/baz?post_id=240

do i need to set anything in the route buildlink?? (that's what i don't want to do:/
have you tried:
{xen:link 'foobar/baz', '', 'post_id={$post.post_id}'}
 
R

ragtek

Guest
#11
Tried. Doesn't work for me.
ups
sorry, hadn't checked it before posting:D


it seems that it's not possible to do it with the id:(

you'll need the node name
node_name = xxx (node name) works for me:)

<a href="{xen:link 'pages', {xen:array 'node_name=test2dddaads'}}">Link to page</a>
 

Brogan

XenForo moderator
Staff member
#12
Far easier just to do this, surely?

<a href="{xen:link 'pages/page-title/'}">Page link</a>

Unless you're doing it programmatically of course.
 
A

account8226

Guest
#14
If I have my own link (custom add-on), how could I add something like /myroute/subroute/ID/do-that using the {xenlink} syntax ?
 

tenants

Well-known member
#15
I'm looking back at this old post, and there is some information missing... And it seemed that many people here were asking the same question in a round about way.

If you have your own route prefix for a given add-on ... for instance, lets say you have a blogs add-on, and you want to create a <xen:link in the template such as:

<xen:link blogs/edit $thisBlog>

and expect that to return

myforum.com/blogs/my-first-blog.1/edit


In order to do this, you need to create "public function buildLink" in your route prefix

Example:

PHP:
<?php
class SomeBlogPlugin_Route_Prefix_Blog implements XenForo_Route_Interface
{
 
    public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    {
        $action = $router->resolveActionWithIntegerParam($routePath, $request, 'node_id');
        return $router->getRouteMatch('SomeBlogPlugin_ControllerPublic_Blog', $action, 'blog');
    }
 
 
    public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
    {
        return XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, $extension, $data, 'node_id', 'title');
    }
 
}


So now in your template, as long as $thisBlog contains $thisBlog['node_id'] and $thisBlog['title']

<xen:link blogs/edit $thisBlog> will resolve as myforum.com/blogs/[title].[node_id]/edit

or from Kiers example, now that you have the buildLink function for your router you can simply use:

<xen:link blogs/edit {xen:array 'node_id={$node_id}', 'title={$title}'}>


If I have my own link (custom add-on), how could I add something like /myroute/subroute/ID/do-that using the {xenlink} syntax ?
In your case , since you only want to resolve the id (and not the title too), your public function buildLink for the "something" route prefix would contain

Code:
    public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
    {
        return XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, $extension, $data, 'id');
    }
So now, when you use <xen:link something/do-that $thisThing> in your template, this will resolve as forum/something/ID/do-that (as long as $thisThing contains id)
 

Liam W

Well-known member
#16
I'm looking back at this old post, and there is some information missing... And it seemed that many people here were asking the same question in a round about way.

If you have your own route prefix for a given add-on ... for instance, lets say you have a blogs add-on, and you want to create a <xen:link in the template such as:

<xen:link blogs/edit $thisBlog>

and expect that to return

myforum.com/blogs/my-first-blog.1/edit


In order to do this, you need to create "public function buildLink" in your route prefix

Example:

PHP:
<?php
class SomeBlogPlugin_Route_Prefix_Blog implements XenForo_Route_Interface
{
 
    public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    {
        $action = $router->resolveActionWithIntegerParam($routePath, $request, 'node_id');
        return $router->getRouteMatch('SomeBlogPlugin_ControllerPublic_Blog', $action, 'blog');
    }
 
 
    public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
    {
        return XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, $extension, $data, 'node_id', 'title');
    }
 
}


So now in your template, as long as $thisBlog contains $thisBlog['node_id'] and $thisBlog['title']

<xen:link blogs/edit $thisBlog> will resolve as myforum.com/blogs/[title].[node_id]/edit

or from Kiers example, now that you have the buildLink function for your router you can simply use:

<xen:link blogs/edit {xen:array 'node_id={$node_id}', 'title={$title}'}>




In your case , since you only want to resolve the id (and not the title too), your public function buildLink for the "something" route prefix would contain

Code:
    public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
    {
        return XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, $extension, $data, 'id');
    }
So now, when you use <xen:link something/do-that $thisThing> in your template, this will resolve as forum/something/ID/do-that (as long as $thisThing contains id)

Excellent, thanks!

Now, how do I get the data back from the URL?
 

tenants

Well-known member
#17
In your template, you would have something like this:
Code:
<xen:link blogs/edit $blog>
which would resolve as this: myforum.com/blogs/my-first-blog.1/edit (as long as the array $blog contains 'node_id' and 'title')

In your route prefix, you would define
Code:
$action = $router->resolveActionWithIntegerParam($routePath, $request, 'node_id');
In your controllerPublic you would have an action "actionEdit" and this would contain
Code:
$nodeId = $this->_input->filterSingle('node_id', XenForo_Input::UINT);
and then you would do a look up to get the data needed for that node_id
Code:
$thisBlog =  $blogModel->getBlogById($nodeId);
 
#18
@Kier Can you help me with that:
How to get thread link by post id (in node_forum_level_2)?

Or How can I change the lastPost link
Code:
<a href="{xen:link posts, $forum.lastPost}" title="{$forum.lastPost.title}">{$forum.lastPost.title}</a>
From this
Code:
forum/posts/66/
to this
Code:
forum/threads/zadat-vopros-vrachu.18/#post-66
 
Last edited: