1

I have created a custom variable in magento. But I want to call a template file for this variable value.

For this I am using

{{block type="core/template" template="custom/my.phtml"}}

in Variable HTML Value field.

But when adding this variable in any email template like {{customVar code=my_var}} then print

{{block type="core/template" template="custom/my.phtml"}}

as it is.

How to add a template file in custom variable HTML value?

3

you can add your phtml file in email template simple add the like this and add your coding in template.phtml.

{{block type='core/template' area='frontend' template='my/template.phml'}}
| improve this answer | |
  • Thank you, it is working in my case but without area='frontend'. – Vinaya Maheshwari Jul 14 '16 at 12:25
1

You can't. Custom variables are designed to be used the other way around: you can output the value of a custom variable in your templates. They are not parsed in any way.

If you want to output a template file in another template, you could do two things:

  1. Add it in your layout xml as a child block, give it an alias (let's say 'demoblock') and then output it in your original template as <?php echo $this->getChildHtml('demoblock'); ?>
  2. Dynamically create a block and display it's output: <?php echo $this->getLayout()->createBlock('core/template')->setTemplate('theme/my.phtml')->toHtml(); ?>
| improve this answer | |
  • I want to add voucher code with customer new account email, for this I have created a custom variable, but need to add some php code, so I wants to add template file. – Vinaya Maheshwari Jul 14 '16 at 11:34
  • In that case, you can better add a widget or whitelist a block (in System » Permissions » Blocks) and use it in your email like {{block type="core/template" template="my/template.phtml"}} – Mark van der Sanden Jul 14 '16 at 12:22
1

You can do that through layout in your email template.

Step 1: add this {{layout handle="customer_email_template_custom"}} in your email template.

Step 2: Add handle in your theme local.xml.

<customer_email_template_custom>
        <block type="core/template" name="my.custom" template="my/template.phml"/>
</customer_email_template_custom>

then you can add your php code in that phtml file.

I have refer order_new email template.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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