• 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 ?

allewreK

Active member
#1
Hello,

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.
 

Chris D

XenForo developer
Staff member
#2
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:

Code:
{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:

PHP:
$__output = '';
$__output .= (1 + 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

Active member
#3
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:

Code:
{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:

PHP:
$__output = '';
$__output .= (1 + 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.
Thanks you very much Chris, I wanted to make sur it's the exact same :)