i've tried:It won't contain the title, but it will work and it's future proof.HTML:<a href="{xen:link 'threads', {xen:array 'thread_id={$threadId}'}}">Link to thread</a>
have you tried: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:/
upsTried. Doesn't work for me.
<?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');
}
}
If I have my own link (custom add-on), how could I add something like /myroute/subroute/ID/do-that using the {xenlink} syntax ?
public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
{
return XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, $extension, $data, 'id');
}
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)
<xen:link blogs/edit $blog>
$action = $router->resolveActionWithIntegerParam($routePath, $request, 'node_id');
$nodeId = $this->_input->filterSingle('node_id', XenForo_Input::UINT);
$thisBlog = $blogModel->getBlogById($nodeId);
<a href="{xen:link posts, $forum.lastPost}" title="{$forum.lastPost.title}">{$forum.lastPost.title}</a>
forum/posts/66/
forum/threads/zadat-vopros-vrachu.18/#post-66
Thanks Mike! I need that to remove 301 redirect. So can you help me? Where can I read about this? Or something ...That would require custom development/an add-on. It's not just a template change.
We use essential cookies to make this site work, and optional cookies to enhance your experience.