Magento {{depend}} combined with {{config path='some/value/here'}}
-
16-10-2019 - |
Pergunta
we are using the {{depend}} functionality to check for true on a system config variable
But now we are running into the following. Can I combine these special {{}} tags within each other? For example if I want to check config path='some/value/here' to be TRUE, would I do it as follows?
{{depend {{config path='some/value/here'}}}} text here
Question: How can I use the depend to check a config path value?
And maybe a second question is: does depend check for empty, or does it also understand yes and no's from the config?
Many thanks
Solução
You cannot use {{depend}}
and {{config}}
in that combination for 2 reasons.
The first and most important is that the regex match is screwed up like this. If you have a text like this {{depend name}} some text {{/depend}}
the matches array looks like this:
Array
(
[0] => Array
(
[0] => {{depend name}} some text {{/depend}}
[1] => name
[2] => some text
)
)
This means that if the value for the variable name
evaluates to something else than null
false
0
the value in [0] (the expression) will be replaced with the value from [2] (some text).
If you try it with {{depend {{config path="some/path/here"}}}} some text {{/depend}}
the matches look like this:
Array
(
[0] => Array
(
[0] => {{depend {{config path='some/path/here'}}}} some text {{/depend}}
[1] => {{config path='some/path/here'
[2] => }} some text
)
)
The second reason is that the depend conditions must be a variable passed to the template (element inside the _templateVars
member).
The work around for this is to pass the value from the config as a variable to the template and then use that variable in the depend
statement.
Let's take for example the new order e-mail sending. In Mage_Sales_Model_Order::sendNewOrderEmail()
$mailer->setTemplateParams(array(
'order' => $this,
'billing' => $this->getBillingAddress(),
'payment_html' => $paymentBlockHtml
)
);
Turn it into this:
$mailer->setTemplateParams(array(
'order' => $this,
'billing' => $this->getBillingAddress(),
'payment_html' => $paymentBlockHtml,
'my_config_var'=> Mage::getStoreConfig('some/path/here')
)
);
Now you should be able to use:
{{depend my_custom_var}} some text {{/depend}}