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

Performance : should we make our calculs in templates with xen:calc, or in PHP ?

Discussion in 'XenForo Development Discussions' started by allewreK, Nov 10, 2013.

  1. allewreK

    allewreK Active Member


    I need to make a lot of calcs, but I wanted to know what would be the faster way : doing that with xen:calc in templates, or doing the calcs with normal PHP operators in my model/controller ?

    Best regards.
  2. Chris D

    Chris D XenForo Developer Staff Member

    It's the same.

    XenForo compiles templates containing various bits of xen: syntax and other stuff into a compiled and executable PHP script.

    An example is if you create a template (let's call it test_1) with contents:

    {xen:calc '1 + 1'}
    That is saved in the xf_template table.

    If you check xf_template_compiled table and find the test_1 template:

    $__output '';
    $__output .= (1);
    The template compiler has literally taken the xen syntax and converted it into the PHP equivalent:

    (1 + 1)

    So effectively whether you do the calc in the template or whether you use PHP functions it's the same.
    allewreK and Brogan like this.
  3. allewreK

    allewreK Active Member

    Thanks you very much Chris, I wanted to make sur it's the exact same :)

Share This Page