Using Custom Helpers with Handlebars
Hi,
I am using the latest version of the "Trigger Email" extension. I am trying to use a custom helper by declaring it in my HTML but it doesn't work as I get the error
Error: Missing helper: "getProductUnit"
I am not sure how to implement those custom helper in the email-template, here is what I tried :
<html>
<head>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>.......</title>
<script type="text/javascript" src="handlebars-v2.0.0.js"></script>
<script type="text/javascript">
Handlebars.registerHelper("getProductUnit", function(product) {
return "hello"
});
</script>
</head>
<body class="">
{{getProductUnit product}}
</body>
</html>```
Thank you for your help
I'm not 100% sure, but shouldn't the Handlebars library only be used on a server environment and not on the client?
Correct -- Handlebars here is only being used in the Cloud Function created by the Extension. There is currently no way to create custom helpers for the extension.
What I'd recommend you do instead is (depending on how your email needs to be triggered) create a callable Cloud Function that will generate the HTML for the email using whatever libraries you like and then adds the rendered HTML to the mail collection from the function.