Magento 1.9 CMS Static Blocks – Using Variables with {{depend}}

cmsemail-templatesmagento-1.9template-directive

I have used the {{depend}} template functionality before using email templates and I am wondering if this is possible within CMS Static Blocks, for example:

<a href="{{store url='customer/account'}}">Login/Account</a>

Could be updated to:

<a href="{{store url='customer/account'}}">
  {{depend loggedIn}}Account{{/depend}}
  {{depend loggedOut}}Login{{/depend}}
</a>

Which could be useful to allow customers the option to update these within the CMS Block whilst keeping the dependency functionality.

Obviously this dependency depends on the variables being available to the block itself which the email template achieves using the following (which could be applied to the cms block/model with a rewrite):

public function setTemplateParams(array $templateParams)
{
    return $this->setData('template_params', $templateParams);
}

What I am unsure on is how the templating language used within the block accesses this information, adding {{depend}} tags to a block simply outputs as plain text. I assume there is a compilation step applied before the html is rendered, but a nudge in the right direction as to how to proceed would be of great help.

Best Answer

This is not an answer to the question, but it might be a solution to the problem.
I don't think it's a good idea to do all kinds of rewrites. You can achieve the same thing by creating a block and a template and using that in your static block.

Create the block [Namespace]/[Module]/Block/Link.php with this content:

<?php 
class [Namespace]_[Module]_Block_Link extends Mage_Core_Block_Template
{

    public function getAccountUrl()
    {
        if (Mage::getSingleton('customer/session')->isLoggedIn()) {
            return $this->getUrl('customer/account');
        } 
        return $this->getUrl('customer/account/login');
    }
    public function getLabel()
    {
        if (Mage::getSingleton('customer/session')->isLoggedIn()) {
            return Mage::helper('customer')->__('Account');
        } 
        return Mage::helper('customer')->__('Login');
    }
}

then create the template app/design/frontend/base/default/template/[namespace]_[module]/link.phtml

<a href="<?php echo $this->getAccountUrl()?>"><?php echo $this->getLabel()?></a>

Now add this in your cms block

{{block type="[block_alias]/link" template="[namespace]_[module]/link.phtml"}}