How Can You Find Out What Variables are Available in Templates?

Kier

XenForo Developer
Staff member
#1
The following is a little presentation I put together during alpha testing, in which I demonstrated how to find all the action-specific variables that are available for you use in templates. Variables such as $xenOptions and $visitor are not included, as they are available on every page regardless of action.

Enjoy :)

 

NolF

Active member
#3
:O had I known about Zend studio, I could have saved so many ours back in the day. Thanks for the tutorial Kier, it's exactly the type of think I need to start playing with these things :D
 

simunaqv

Well-known member
#7
Hi Kier, thanks for posting this useful information. I have one question regarding variable dumps. Is it possible to use FirePHP for dumping variables in browser consoles?
 

Benjy

Well-known member
#12
Hi,
I don't know if this is a bug, but while trying to add some info next to the thread title, I went and edited the PAGE_CONTAINER template, adding something along these lines :
Code:
<xen:if is="{$contentTemplate} == 'thread_view'"> by {$thread.username}</xen:if>
Well, no username is written (the condition works because I see the "by") so it seems thread.* data isn't available in the top-level template?
 

Jeremy

Well-known member
#13
Hi,
I don't know if this is a bug, but while trying to add some info next to the thread title, I went and edited the PAGE_CONTAINER template, adding something along these lines :
Code:
<xen:if is="{$contentTemplate} == 'thread_view'"> by {$thread.username}</xen:if>
Well, no username is written (the condition works because I see the "by") so it seems thread.* data isn't available in the top-level template?
Not all variables available to one template is available to another. {$thread} is available in one, is not necessarily available in another. You must find a variable available in that template to suit your needs, or to modify the PHP via an add-on to inject your variable.
 

tenants

Well-known member
#14
Sometimes you don't have all the variables you need to override a given template, so how do you bring others in?

For instance, I'm overriding page_container_content_title_bar
However, I need to know if the user is the "thread creator".
I've check through all the variables, and it doesn't look like there is anything available

I can get visitor.id, and contentTemplate.template is thread_view

How do I bring other variables that I need into a template, the listener I'm using is as follows:

PHP:
class myPlugin_Listener
    public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template) {
        if ($hookName == 'page_container_content_title_bar') {
            $contents = ($template->create('mytemplate', $template->getParams() ));
            //.var_export( $template->getParams()); // add this to the contents to dump out all the available varibles
        }
    }
}
$template->getParams() will get the params of this template, can I somehow just add to this to push through other params?
 
R

ragtek

Guest
#15
Since some versions it's possible to use the DEFAULT template to get all available variables!

Replace the template title (to DEFAULT) to get the Debug Output
PHP:
return $this->responseView('Ragtek_AS_View_Article', 'ragtek_article_view', $params);
PHP:
return $this->responseView('Ragtek_AS_View_Article', 'DEFAULT', $params);
shows =>
defaultoutput.png
 

tenants

Well-known member
#16
Now that is useful, thanks ragtex.
I assume there is a cost (extra sql), or does it pull in the params from the container element if they exist / cached (I guess the only way to know, is to give it a go)

Once again, thanks
 
Top