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

Using variables in templates

Brogan

XenForo moderator
Staff member
#1
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...
 

wang

Well-known member
#2
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

Brogan

XenForo moderator
Staff member
#3
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.
 

wang

Well-known member
#4
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

XenForo moderator
Staff member
#5
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:
Code:
<xen:container...
Read the rest of this update entry...
 

Brogan

XenForo moderator
Staff member
#6
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
Code:
lorem_ipsum_dolor_sit_amet_x
The x in the title is commonly used to...
Read the rest of this update entry...
 

Brogan

XenForo moderator
Staff member
#7
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...
 

woody

Active member
#8
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 :)
 
#11
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>
 

Brogan

XenForo moderator
Staff member
#14
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.
 

Brogan

XenForo moderator
Staff member
#18
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.
 

Senpai

Formerly RamzanHD
#19
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
 

Brogan

XenForo moderator
Staff member
#20
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.