Twig Versus Smarty Modifiers

This works:

{assign var="myvar" value=$plan->plan_id|ezvp_simple_plan_category_commissions}

in smarty but for twig, this

{% set myvar = ezvp_simple_plan_category_commissions(plan.plan_id) %}

fails with

Fatal error: Uncaught Twig_Error_Syntax: Unknown "ezvp_simple_plan_category_commissions" function


The function is defined in the func.php of an addon.

Anyone know why this is generating an error?

Update: if fails for standard functions too like fn_get_category_name(category_id).

This works:

{assign var="myvar" value=$plan->plan_id|ezvp_simple_plan_category_commissions}

in smarty but for twig, this

{% set myvar = ezvp_simple_plan_category_commissions(plan.plan_id) %}

fails with


The function is defined in the func.php of an addon.

Anyone know why this is generating an error?

Update: if fails for standard functions too like fn_get_category_name(category_id).

Hey,

You will have to register the functions, it is a security feature from Twig.

$twig->addFunction(new Twig_SimpleFilter('func_in_twig', 'func_in_php')); 

Kind regards,

You woudln't know where in the bowls of cs-cart where they define (and how to access) $Twig would you? I.e. Tygh::$app['twig']?

You woudln't know where in the bowls of cs-cart where they define (and how to access) $Twig would you? I.e. Tygh::$app['twig']?

Hello,

Of course I do :). If you take a look at the providers which are being registered on initialization you can see that the Twig 'renderer' is located in the Tygh::$app['template.renderer'] container. Also, in case you are wondering, the naming is kind of weird in those files, e.g. the new template thing for e-mails is referred to as 'db_template'.

Kind regards,

Thank you. I managed to work around it by passing the variable needed, but good to know for the future.

I really hate working with all the new Twig templates. Cs-cart addons have the advantage that they can distribute their documents/snippets and don't have to figure out how to install them. They expect us to spend the time training the customer on editing a document to include a new snippet or variable.

Anyway do appreciate the pointers.

Thank you. I managed to work around it by passing the variable needed, but good to know for the future.

I really hate working with all the new Twig templates. Cs-cart addons have the advantage that they can distribute their documents/snippets and don't have to figure out how to install them. They expect us to spend the time training the customer on editing a document to include a new snippet or variable.

Anyway do appreciate the pointers.

Hey,

Cant agree more. The most baffling thing is that they expect us to write the documentation for others as well. As attractive as that may sound, it is a very bad business model.

Also, what might help in these situations is a different IDE (as crazy is it may sound). PHPStorm offers many advantages, it allows you to debug programs in real time and it gives you awesome shortcuts (e.g. CTRL + Click on a function and it will open it in a seperate tab). It is definetely worth the money.

Kind regards,