Using variables in templates

Using variables in templates

Paul B

XenForo moderator
Staff member
Brogan submitted a new resource:

Using variables in templates - $bro.guide

It's not always obvious whether a variable will work in a template.

By variable I mean something like $forum, $thread, $post, etc.
These would typically be used in conditional statements, utilising the node, user, or position ID, for example $forum.node_id, $thread.user_id, $post.position.

There is, however, an easy way to check whether a variable is available and can therefore be used in a statement.

Read more about this resource...
 
Excellent guide sir.

I tried to rate it and leave a review too, but the Submit button was greyed out and it could not be submited.
 

Attachments

  • rating.webp
    rating.webp
    46.9 KB · Views: 28
Did you write some comments in the Review field?

The button should become active once you reach the minimum character count, which is currently 100.
 
Yes sir. I wrote this review.

Excellent guide sir. Thank you for posting it.

Edit. I saw where the problem was. I lengthened the review and now it was posted.
 
Last edited:
Brogan updated Using variables in templates with a new update entry:

Setting values in the container

Although a variable may not be natively available in a template, in some cases it is possible to set the value of it in the container using <xen:container>.

The container encompasses the PAGE_CONTAINER template and all templates included by it, such as category_view, pagenode_container, various ad_* templates, etc.

To set a variable in the container, this code must be added to the content template:
Rich (BB code):
<xen:container...

Read the rest of this update entry...
 
Brogan updated Using variables in templates with a new update entry:

Calling variables in phrases

If a variable is available in a template, you can use it in a phrase which is included in that template.
The benefit over just adding the phrase(s) and variable(s) to the template separately is that only a single phrase is required no matter how many variables are called or where they are inserted in the phrase.


The phrase title and text take the form:
Title
Rich (BB code):
lorem_ipsum_dolor_sit_amet_x
The x in the title is commonly used to...

Read the rest of this update entry...
 
Brogan updated Using variables in templates with a new update entry:

Calling Options & Style Properties in templates

It is possible to call Option and Style Property values and settings directly in templates.

In order to identify the option or style property name, debug mode must be enabled.
To do that, edit the library/config.php file and add this at the very bottom:
PHP:
$config['debug'] = true;
Note: Once debug mode is no longer required, it is recommended that it is disabled. Debug mode should not be enabled on a production site and it can also result in the inadvertent editing of the master...

Read the rest of this update entry...
 
Excellent guide...have been using this with DFP variables to call specific ads based on template, visitor ID and others.

Question: is there a variable that notes the canonical URL? I'm working on some new targeting options for DFP and it would be very useful to pull that specific information.

Thank you @Brogan :)
 
Still seeking a means of dynamically passing the page URL into DFP for targeting purposes...
 
I don't really understand what it is you're after but there's unlikely to be a variable for it.
 
Still seeking a means of dynamically passing the page URL into DFP for targeting purposes...

Something like this?
Code:
<script>

    var strCurrentPage = "{$contentTemplate}";
    googletag.pubads().setTargeting("page",strCurrentPage);
   
    <xen:if is="{$forum.node_id} != 0">
        // if not homepage, send forum id:
        googletag.pubads().setTargeting("forumid","{$forum.node_id}");
   </xen:if>


</script>
 
Add this to the pagenode_container template:
Code:
<xen:container var="$pagenode_id">{$page.node_id}</xen:container>


That will make the page node ID available in the head section of the PAGE_CONTAINER template.
 
if i wanted to add something to certain members postbit "Potential Scammer " how would i do it using variables
 
There is no 'potentialscammer' variable so you would either have to create one somehow, or use a conditional statement based on group membership.

Hence why the user group and banner option is the intended use case for that scenario.
 
There is no 'potentialscammer' variable so you would either have to create one somehow, or use a conditional statement based on group membership.

Hence why the user group and banner option is the intended use case for that scenario.
no what i wanted to do is add test text to postbit for example member id 1
 
I really don't understand what it is you are trying to do, but a conditional statement would be more suited - this guide isn't intended for that use case.
 
Top Bottom