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

Using an Alternative Page Container

Discussion in 'Official Development Tutorials and Resources' started by Kier, Feb 2, 2011.

  1. Kier

    Kier XenForo Developer Staff Member

    Add-on developers will likely have noticed that (almost) all XenForo output for the public-facing side of the application is contained within a single template, called PAGE_CONTAINER.

    Individual page templates only allow you to build the HTML within the content area, though there are various XenForo template syntax systems that allow you to pass commands and data to the container, the most obvious of which is the ubiquitous <xen:title>Page Title Here</xen:title> here construction.

    However, as time goes on and add-on applications grow more complex, you are likely to find that you want to output your data into your own custom container. The good news is, it's easy to do so. All you need to do it pass a containerTemplate variable to your view layer.

    Here's an example of how to do that:
    class MyAddOn_ControllerPublic_Something extends XenForo_ControllerPublic_Abstract
        public function 
    // do stuff here to build $viewParams array and then...

    return $this->responseView(
    'MyAddOn_ViewPublic_Something_Index'// view name
    'some_template'// content template name
    $viewParams//  data to be passed to content template
    array('containerTemplate' =>
    'MyAddOn_Page_Container_Template'// your own container template
    The only thing to note here is how we pass containerTemplate as a value of the array that is the fourth argument to responseView().

    Of course, if you decide to use your own container template, you need to handle everything yourself. Breadcrumbs, headers and footers, sidebars... all that stuff is handled by the container template and if you don't implement something in your own container template, it won't be there when content templates call for it. Study the default PAGE_CONTAINER template for everything you need to know.
    K_Rivers, lsxforo, Thomas.B and 23 others like this.
  2. Kier

    Kier XenForo Developer Staff Member

    ^ That post is getting very lonely all by itself, so here is a reply.
    Jeremy, patrick91 and Bob like this.
  3. Floris

    Floris Guest

    *lonely bump* :p

    This is great to hear, and helps me customize my style in a unique enough way so I do not have to worry about upgrades just because I have a few unique sections on the sites. And I can leave page_container basically alone.
  4. ragtek

    ragtek Guest


    thx for the post^^
    I've done this some time ago very ugly because i hadn't seen
    $templateName = (!empty($params['containerTemplate']) ? $params['containerTemplate'] : 'PAGE_CONTAINER');
    (created own dependencies where i overwrote the getViewRenderer...:D )
    hoaquatrai likes this.
  5. Peggy

    Peggy Well-Known Member

    Well, I would have replied, but, see, here's the problem....

    I have NO idea wth you're talking about. :)
    HeadHodge, hoaquatrai, Wuebit and 3 others like this.
  6. ericdes

    ericdes New Member

    @Kier: I'm a bit lost as for how to choose among the offered listeners. What would be a typical code event listener that would trigger your class in an add-on?
    hoaquatrai likes this.
  7. GofD

    GofD Well-Known Member

    That's the one and perhaps only problem I see with likes. Lots of people LIKED your post, but noone replied until you bumped it. Well, that and maybe Like Abuse.
    hoaquatrai, Digital Doctor and James like this.
  8. gordy

    gordy Well-Known Member

    Yer.. about only a handful of people do, even more confusing there is no example :D
  9. masterchief

    masterchief Well-Known Member

  10. masterchief

    masterchief Well-Known Member

    more sample page containers????
  11. ragtek

    ragtek Guest

    We're not talking about the normal xf pages (node type)

    It's about the output from controllers.
  12. masterchief

    masterchief Well-Known Member

    examples to share at all??
  13. pegasus

    pegasus Well-Known Member

    Thanks for explaining this. Saved me a lot of time and frustration today (and by extension, people's lives).
    Digital Doctor likes this.
  14. HeadHodge

    HeadHodge Member

    I'm interested in doing this.
    In your post, is 'MyAddOn_Page_Container_Template' a PHP or HTML file? I'm thinking PHP but would like confirmation. Thanks....
  15. HeadHodge

    HeadHodge Member

    Or I guess it could be another template with the name: "MyAddOn_Page_Container_Template".
    I was thinking it was a physical file named "Template" in the MyAddOn\Page\Container directory.
  16. HeadHodge

    HeadHodge Member

    I tried this today, with limited success. I created a new template for my custom container and to prove it was working I copied the contents of the template "PAGE_CONTAINER" to my new template. The resulting page was close to the original, but it was missing a few things. The background gif was missing as well as the little icon for the background picker.

    Anyone have any idea why that would be? I would really like to get it working properly, but can't figure out the background issue. :(

Share This Page