Magento – Email template and custom variables acting very strange

emailemail-templates

i've been debugging this for hours now. And I am just dumbstruck what it could be. We use a customvar in an email template. I will try to explain as good as possible.

USECASE 1: If I place {{customVar code=SOCIALBUTTONS}} @ the bottom of the email then the variable contained in the customVar {{config path='web/unsecure/base_url'}} the results is: variable not parsed for its value. (you can read the variable declaration: {{config path='web/unsecure/base_url'}})

USECASE 2: If I place the {{customVar code=SOCIALBUTTONS}} somewhere in my email template a second time – higher up: both variables have my domain for {{config path='web/unsecure/base_url'}}: storename.com

USECASE 3: If I place the {{customVar code=SOCIALBUTTONS}} higher in my email template only once – the variables have my domain for {{config path='web/unsecure/base_url'}}: storename.com

My question is: how can this be? I have been searching through the code looking for a mistake … I just dont get it

<div style="font:1em/1.4em arial,verdana,sans-serif; margin:1px;border:1px solid DarkSlateGray;color:DarkSlateGray">
<div style="background:white;padding:2px 6px;color:DarkSlateGray;text-align:right; font-size:0.8em;-webkit-text-size-adjust:none;">
<a style="color:sienna;text-decoration:none" href="{{config path="web/unsecure/base_url"}}">website</a> | 
<a style="color:sienna;text-decoration:none" href="{{config path="web/unsecure/base_url"}}contact">contact</a> | 
<a style="color:sienna;text-decoration:none" href="{{config path="web/unsecure/base_url"}}veelgesteldevragen">faq</a> | 
<a style="color:sienna;text-decoration:none" href="{{config path="web/unsecure/base_url"}}algemene-voorwaarden">voorwaarden</a></div>
<div style="padding:4px 6px;font:1.6em 'Arial Black',arial,sans-serif;color: white;background:SteelBlue;">{{config path="general/store_information/name"}}</div>

<!-- INTRODUCTIE TEKST -->
<div style="background:white;padding:4px 6px;color:DarkSlateGray">
<p><span style="font-size:1.6em;color:sienna;">Hi {{htmlescape var=$billing.getFirstname()}}!</span></p>
<p>Vandaag wordt je bestelling verzonden met PostNL. De meeste verzendingen arriveren de volgende werkdag met uitzondering van een klein percentage dat een werkdag later volgt. Voor verzending op vrijdag, zaterdag of zondag arriveert het pakketje vaak maandag en heel soms dinsdag.</p></div>

{{customVar code=NEWSLETTER}}

<!-- GEGEVENS VAN BESTELLING -->
<div style="padding:4px 6px;font:1em 'Arial Black',arial,sans-serif;color: white;background:SteelBlue;">Bestelling #{{var order.increment_id}}</div>
{{depend comment}}<div style="background:white;padding:4px 6px;color:DarkSlateGray"><p>Opmerking bij bestelling: {{var comment}}<br />{{/depend}}
{{depend order.getEmailCustomerNote()}}<br />Notitie bij bestelling: {{var order.getEmailCustomerNote()}}</p></div>{{/depend}}

<table style="width:99%; margin: 4px 0"><thead><tr style="font:1em 'Arial Black',arial,sans-serif;color: SteelBlue;">
<th style="text-align:left;white-space:nowrap;padding-left:6px; width: 50%">Verzending</th>
<th style="text-align:left;white-space:nowrap; width: 50%">Betaling</th>
</tr></thead>
<tbody><tr>
<td style="padding-left:6px;background:white;vertical-align: top;"><p>{{var order.getShippingDescription()}}</p>{{var order.getShippingAddress().format('html')}}</td>
<td style="background:white;vertical-align: top;">{{var payment_html}}{{var order.billing_address.format('html')}}</td>
</tr></tbody></table>

<div style="padding:4px 6px;font:1em 'Arial Black',arial,sans-serif;color: white;background:SteelBlue;">Bestelgegevens</div>
<div style="background:white;padding:4px 4px;color:DarkSlateGray">{{layout handle='sales_email_order_items' order=$order}}{{var items_html}}</div>

<div style="padding:4px 6px;font:1em 'Arial Black',arial,sans-serif;color: white;background:SteelBlue;">Bedankt namens ons</div>
<div style="background:white;padding:4px 6px;color:DarkSlateGray">
<p>Bedankt voor je order bij <a target="_blank" href="{{config path='web/unsecure/base_url'}}" style="color:sienna">{{config path='general/store_information/name'}}</a>.</p>
<p>En heb je nog een vraag of opmerking? Antwoord dan op dit bericht. Of neem een kijkje bij de <a target="_blank" href="{{config path='web/unsecure/base_url'}}veelgesteldevragen" style="color:sienna">veelgestelde vragen</a> op onze website.</p></div>

{{customVar code=SOCIALBUTTONS}}

<!-- CLOSING DIV -->
</div>

Thanks in advance

Best Answer

In your template you could use a custom block like this

{{block type='fooman_example/email' config_var='SOCIALBUTTONS'}}

and then in your block based on Mage_Core_Model_Email_Template_Filter

<?php
class Fooman_Example_Block_Email extends Mage_Core_Block_Template
{

    protected function _toHtml()
    {
        $customVarValue = '';
        $variable = Mage::getModel('core/variable')
            ->setStoreId(Mage::app()->getStore()->getStoreId())
            ->loadByCode($this->getConfigVar());
        if ($value = $variable->getValue(Mage_Core_Model_Variable::TYPE_HTML)) {
            $customVarValue = $value;
        }
        return $customVarValue;
    }
}