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

Including html/php to templates...

Discussion in 'XenForo Development Discussions' started by Umit, Mar 17, 2011.

  1. Umit

    Umit Active Member

    Hi, I've created a very basic addon and trying to includes a html file (it is a weather forecast data) to sidebar.

    here is my addon;
    class XenForo_Umiweather_kusweather
        public static function container_public_params(array &$params, XenForo_Dependencies_Abstract $dependencies)
            $kusweather = ob_get_contents();
            $params = array(
                'kusweather'  => $kusweather
    /*$dependencies->params = array_merge(
    Code Event Listener: container_public_params

    I can add this to page_include template and it is working but breaking javascript of the website.

    I dont know what i am doing wrong but first i want to get rid of the errors and second i want to add the output to any template (for example sidebar templates).

    Please help...
  2. Jeremy P

    Jeremy P Well-Known Member

    Just a thought, try $params += array(...

    Otherwise you're probably going to need to provide more information. How is the javascript broken? Are there messages in the console? What is the contents of the weather html?
    Umit likes this.
  3. Umit

    Umit Active Member

    Ohhh! That sorted out some errors. Thank you so much Jeremy.

    But still, i can only use it on page_container, how can i use it in sidebar related templates?
  4. Jeremy P

    Jeremy P Well-Known Member

    Hmm. You could try adding a <xen:sidebar> block to page_container, not sure if that would override or just append/prepend to pages where one already exists. Otherwise you'd probably have to use template hooks, or extend load_class_controller for the controllers of the templates you want the variable to be available in.
    Umit likes this.
  5. Umit

    Umit Active Member

    Thank you again Jeremy,

    just want to add this {xen:raw $kusweather} to sidebar_online_users template, dont want to use page_container.

    should i change "listen to event: container_public_params" to something else?
  6. Jeremy P

    Jeremy P Well-Known Member

    Maybe adapt your listener for template_create?
    Then when that template is created pass that as a param? Not 100% that would work though, it might not catch <xen:include> statements, I haven't looked much into how templates work/are compiled.

    Otherwise you'd have to extend the controllers, pass that variable to the view parameters, and then edit the templates to include <xen:set var="$kusweather">{$kusweather}</xen:set> between the includes for sidebar_online_users..
  7. Umit

    Umit Active Member

    Thank you Jeremy, how can i extend the controllers?
  8. Jeremy P

    Jeremy P Well-Known Member

    Umit likes this.
  9. ragtek

    ragtek Guest

  10. Umit

    Umit Active Member

    Thank you so much Jeremy and Ragtek. Template hooks working perfectly. Cant believe it is so easy.

    But i have a question; what if the template does not contain any hook? then can we create something like this in the template;

    <xen:hook name="our_custom_hook_name" />
  11. Jeremy P

    Jeremy P Well-Known Member

  12. Umit

    Umit Active Member

    hmmm... just tried and didnt work...
  13. Jeremy P

    Jeremy P Well-Known Member

    Should if your code is right.
    public static function templateHook($hookName, &$contents, array $hookParamsXenForo_Template_Abstract $template)
            switch (
    $weather 'weather';
    $contents .= $weather;
    Umit likes this.

Share This Page