Reputation: 967
I needed to create a specific email template sent using an observer running from a cron.
When I received the email, I don't have the value of the provided variables.
$vars = array(
'product' => $product,
'customer' => $customer
);
$mailTemplate->sendTransactional(
$mailId,
'general',
$customer->getData('email'),
$customer->getData('firstname') . ' ' . $customer->getData('lastname'),
$vars
);
$product
& $customer
are both object from a Model Collection (Product_Collection & Customer_Collection).
In my template, I'm trying to access them like this:
Dear {{htmlescape var=$customer.name}},
<p>Check {{htmlescape var=$product.name}}</p>
Any ideas?
By the way, how can I construct url to my product? (to let the customer click on a link to view the product)
Upvotes: 1
Views: 4203
Reputation: 777
These parameters are tokenized while the part before the .
is considered the object and string after is the method
to be called on that object.
So $customer.name
is evaluated to $customer->name()
during template processing. To retrieve the customer's name you would call $customer->getName()
in PHP, therefore use $customer.getName()
in the template.
But there is an important difference in how the parameters should be passed for different template methods. As I can gather from the source code, all template methods taking the parameters as a single argument without an attribute assignment should be called without the leading $
while all methods using an attribute require the $
as prefix.
Attribute assignment
{{htmlescape var=$customer.getName()}}
But as a single param
{{var customer.getName()}}
Find all available methods in the class Mage_Core_Model_Email_Template_Filter
by looking at the *Directive()
functions.
Upvotes: 2
Reputation: 27119
Try it without the dollar signs on your variables. Looking at the default email templates, they do not appear to contains those dollar symbols.
Hope that helps!
Thanks, Joe
Upvotes: 4