1

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

1 Answer 1

5

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}}
4
  • Many thanks Marius. Now we are creating a simple extension that actually only adds some fields in config via system.xml : the question is how would I add this to the extension? (not touching core or other files) .... major thanks
    – snh_nl
    Commented Aug 8, 2013 at 10:45
  • @snh_nl I think this is the subject of an other question. Ask an other one. Anyway... read this: magentocommerce.com/wiki/5_-_modules_and_development/admin/…
    – Marius
    Commented Aug 8, 2013 at 10:56
  • I have read it before ... but can't find the answer here. thanks
    – snh_nl
    Commented Aug 8, 2013 at 11:49
  • ASked another: magento.stackexchange.com/questions/6547/…
    – snh_nl
    Commented Aug 8, 2013 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.