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

How to use XF's built in Template Parser?

Discussion in 'XenForo Development Discussions' started by Jaxel, Jan 14, 2014.

  1. Jaxel

    Jaxel Well-Known Member

    So I am writing an addong, that takes a string, and parses it.
    I would like to use XF's built in template parser, so that I can use code like:
    {xen:if '$var>10', 'true', 'false'}
    So if I have:
    $values = array(
        'var' => '11'
    $template = '<div style="color: {xen:if '{$var}>10', 'red', 'blue'}">test</div>';
    How would I run this through the parser?
    Last edited: Jan 14, 2014
  2. Jeremy

    Jeremy Well-Known Member

    It will be hacky, but you could write a class that extends XenForo_Template_Public, overwrites the __construct() method that sets the params ($this->setParams($params); ), templateName (can be something random), and then takes the $templateName variable and sets Your_Class::$_templateCache['templateName'].

    Then you should be able to do this:

    $rendered Your_Class($template$values)->render();
    Very hacky and hasn't been tested, but theory is sound.
  3. cclaerhout

    cclaerhout Well-Known Member

                $compiler = new XenForo_Template_Compiler($source);
                 $compiled = $compiler->compile('sourceName', $style_id, $lang_id);
                 $readyToUseSource = $__output;

    It might makes the code faster slower to load though.
    Last edited: Jan 14, 2014

Share This Page