XF 2.2 Template variable for thread base url

Syn9

Member
What is the template variable for a thread's base (first page) url?

I've tried {$xf.uri} and {$xf.fullUri} but they include /page-2, etc after them.
 
Solution
There's likely an easier way to achieve what I'm trying to do

If you need the code available in the PAGE_CONTAINER template (presumably because the links are going to be displayed outside the thread and forum pages?) then add this to the thread_view template:
Code:
<xf:page option="thread" value="{$thread}" />

And this to the PAGE_CONTAINER template:
Code:
<a href="{{ link('threads', $thread) }}" rel="nofollow">{$thread.title}</a>
That returns a /threads/thread-title.1/page-2 result, what I'm seeking is a template variable that only returns the base thread url in multi-page threads.

For example, if it's:
Code:
https://www.forum.com/threads/thread-title.1/
https://www.forum.com/threads/thread-title.1/page-2
The first one, or if {$xf.uri} is used then how to strip the /page-2 from it using like {$xf.uri|filter} in a template?
 
At first glance I'm not seeing a function or filter which will strip the last segment of the URI.

You could just manually craft the string using the board URL, thread title, and ID
Code:
{{ $xf.options.boardUrl . '/threads/' . $thread.title|to_lower|urlencode . '.' . $thread.thread_id }}
 
Ok, I gave it a try and the result of using that custom string is:
Code:
https://www.forum.com/threads/.
I'm guessing it's because $thread.title and $thread.thread_id need __globals or context or contentKey etc in order to function in the PAGE_CONTAINER template?
 
Last edited:
You need to pass the thread params to the PAGE_CONTAINER template.

Edit the thread_view template and add this: <xf:page option="thread" value="{$thread}" />.

That will make all thread params available.
 
However, if you are trying to display this on the thread_view template, you can just use this in that template.

Code:
<a href="{{ link('threads', $thread) }}" rel="nofollow">{$thread.title}</a>

It wasn't really clear what you were doing or where you were trying to use it.
 
To clarify, it's in PAGE_CONTAINER so following your advice in #6 and adding a trailing slash, this is what I now have:
Code:
{{ $xf.options.boardUrl . '/threads/' . $thread.title|to_lower|urlencode . '.' . $thread.thread_id . '/' }}
The result it produces on page 2 with the thread title this is a test is:
Code:
https://www.forum.com/threads/this+is+a+test.1/
So we're close to what it should be, which is: https://www.forum.com/threads/this-is-a-test.1/

For some reason it's adding + symbols between the words instead of native -'s is the remaining issue.

There's likely an easier way to achieve what I'm trying to do, which is simply to make multi-page thread titles link to the first page of the topic for a specific Usergroup who requested it.
 
There's likely an easier way to achieve what I'm trying to do

If you need the code available in the PAGE_CONTAINER template (presumably because the links are going to be displayed outside the thread and forum pages?) then add this to the thread_view template:
Code:
<xf:page option="thread" value="{$thread}" />

And this to the PAGE_CONTAINER template:
Code:
<a href="{{ link('threads', $thread) }}" rel="nofollow">{$thread.title}</a>
 
Solution
Back
Top Bottom