1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Official Development Tutorials and Resources' started by Kier, Oct 22, 2010.

  1. Kier

    Kier XenForo Developer Staff Member

    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 :)

     
    TheLaw, Cyb3r, Valhalla and 18 others like this.
  2. yoghurtfarmer

    yoghurtfarmer Well-Known Member

    Is the header the sole of your foot? :confused:
     
    Sean Kendle likes this.
  3. NolF

    NolF Active Member

    :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
     
  4. Corey

    Corey Active Member

    Is anyone else getting this error?
    vimeoprivate.png
     
  5. g0rn

    g0rn Well-Known Member

  6. simunaqv

    simunaqv Well-Known Member

    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?
     
  7. CurveGotti

    CurveGotti Active Member

    Video shows right for me.
     
  8. Luke F

    Luke F Well-Known Member

    Private video here
     
  9. Elizabeth

    Elizabeth Well-Known Member

    Video worked fine for me, LOL
     
  10. Corey

    Corey Active Member

    The video works for me now. :)
     
  11. Benjy

    Benjy Well-Known Member

    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?
     
  12. Jeremy

    Jeremy XenForo Moderator Staff Member

    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.
     
    AlexandrosD likes this.
  13. tenants

    tenants Well-Known Member

    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 $hookParamsXenForo_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?
     
  14. ragtek

    ragtek Guest

    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 and Pepelac like this.
  15. tenants

    tenants Well-Known Member

    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
     
  16. Floris

    Floris Guest

    Fuhrmann likes this.
  17. Morgain

    Morgain Well-Known Member

    There's no video there. Blank space.
     
  18. Corey

    Corey Active Member

    What browser are you on? It's there for me on Chrome. You can view it here also:
    Code:
    http://vimeo.com/14634552
     

Share This Page