XF 1.5 How to get the Thread ID in the Ad templates?

XFuser

Active member
Hello,

How can we get the Thread ID in the Ad Templates?

We have tried several different variations of the thread id variable, but no variation is actually producing the thread id.

We dumped the $forum variable in the Ad Template and it dumps a lot of data but does not show the thread id. Dumping the $page and $thread variable resulted in NULL.

So how can we get the Thread ID in the Ad Templates?

Thank you.
 
We already addressed that in our OP:
Variable $thread is available in ad templates included in thread view.

Or maybe you are trying it in some generic ad template, not specific to thread view? Then you don't have access to anything, so there is nothing you can do without add-on.
 
Variable $thread is available in ad templates included in thread view.

Or maybe you are trying it in some generic ad template, not specific to thread view? Then you don't have access to anything, so there is nothing you can do without add-on.
We are trying to access the Thread ID in the ad_above_top_breadcrumb template while viewing a thread, but dumping $thread returns NULL, so $thread does not seem to be available in the Ad Templates.

Where and how would we use this to access the Thread ID in the ad_above_top_breadcrumb template?
 
Follow the instructions in the guide.

I can't confirm whether it will work - I haven't tested a thread ID.
The instructions are not clear.

Where do we put this code:

Code:
<xen:container var="$variableId">{$variable.id}</xen:container>

What variable name do we use for the Thread ID?

And how do we access that variable in the ad_above_top_breadcrumb template?
 
Add this to any template that is used inside thread, such as one of ad_thread_view_* templates
Code:
<xen:container var="$threadId">{$thread['thread_id']}</xen:container>
Then you'll have access to variable $threadId from container and files included in container, including generic ad templates.
 
Add this to any template that is used inside thread, such as one of ad_thread_view_* templates
Code:
<xen:container var="$threadId">{$thread['thread_id']}</xen:container>
Then you'll have access to variable $threadId from container and files included in container, including generic ad templates.
We just copied and pasted your code above into line 2 of the ad_thread_view_above_messages template , but XF returned the following error upon save:
Code:
The following templates contained errors and were not saved: ad_thread_view_above_messages: 1) Line 2: Template syntax error.
How can we fix this?
 
Sorry, made a typo
Code:
<xen:container var="$threadId">{$thread.thread_id}</xen:container>
That worked. Thank you.
We spoke too soon as it seems your solution only worked on the ad_above_top_breadcrumb template.

We also need $threadid to work on the following templates:
  • ad_below_content
  • ad_message_below
  • ad_thread_view_below_messages
How do we get your solution to also work on those 3 templates above?
 
XenForo renders content in 2 steps: content and container. They have different variables.

In thread view in content block you have $thread variable, in container because of that custom code you have $threadId variable. So if $threadId doesn't work, most likely ad is rendered with content instead of container, so try $thread.thread_id
 
Back
Top Bottom