Jump to content

Template Syntax Errors when else is used


websavers

Recommended Posts

I've been having an odd issue with multiple email templates. It seems like using an {else} results in the following errors in the activity log:

Smarty Error: Syntax error in template "mailMessage:mailMessage:plaintext" on line 33 "{$signature}" unclosed {if} tag

I'm getting this with at least two different email templates. Here's one such template in plaintext for "Invoice Created" the one that the above error is specifically referring to:

<p>Hey {$client_name},</p>
{if $ticket_department eq "Sales"}Since you normally pay with PayPal, you should already have a subscription which will automatically renew on {$invoice_date_due}. If your subscription was previously canceled, then you should use the link below to complete payment manually.{else}According to our records, you normally complete payment with {$invoice_payment_method}, however {$invoice_payment_method} does not support automatic renewal! This means you will need to click the link below to complete payment manually for every invoice we create for you. If you'd like your invoices to automatically renew, without your intervention, we suggest switching your default payment method to a Credit Card or a PayPal Subscription. Just <a href="[snipped]/clientarea.php?action=details">click here to change your default payment method</a>for all invoices within your account. If you'd prefer to continue paying with {$invoice_payment_method}, simply click the link below to proceed.{/if}
<p><strong>Invoice Details</strong></p>
<p>Invoice #{$invoice_num}<br />Default Payment Method: {$invoice_payment_method}<br />Amount Due: {$invoice_total}<br />Date Created: {$invoice_date_created}<br />Due Date: {$invoice_date_due}</p>
<p><strong>Invoice Items</strong></p>
<p>{$invoice_html_contents} <br /> ------------------------------------------------------</p>
<p>You can login to your client area to view and pay the invoice here: {$invoice_link}</p>
<p>{$signature}</p>

Yet the messages seem to send and display just fine. Is it possible the syntax parser is reading the word "if" in the body and thinking it's another {if} statement?

Edited by jas8522
Link to comment
Share on other sites

Near as I can tell, single quotes should be used around things in this; so not "Sales". but 'Sales'. Also be careful about using any quotes within the statement, since that may be seen as special characters and end a statement early. You have several in there, like "you'd" and the URL to pay having double quotes. That's what I'd look at first. 

Edited by bear
Link to comment
Share on other sites

2 minutes ago, bear said:

Near as I can tell, single quotes should be used around things in this; so not "Sales". but 'Sales'. 

Ah! Thanks for the tip: I'll give that a try :)

Sadly their sample code uses double quotes: {if $ticket_department eq "Sales"}

If single quotes solves this, I'll submit that sample code as a bug :P

Edited by jas8522
Add sample code
Link to comment
Share on other sites

1 hour ago, jas8522 said:

Yet the messages seem to send and display just fine. Is it possible the syntax parser is reading the word "if" in the body and thinking it's another {if} statement?

unlikely - if I use your code in a v7.4.1 dev email template, then I see what you see even if I remove the IFs from the text - the email sends, but there is an error in the activity log.

if I type the following directly into the tblemailtemplates database table...

<p>Hey {$client_name},</p>
{if $ticket_department eq "Sales"}
Since you normally pay with PayPal, you should already have a subscription which will automatically renew on {$invoice_date_due}. If your subscription was previously canceled, then you should use the link below to complete payment manually.
{else}
According to our records, you normally complete payment with {$invoice_payment_method}, however {$invoice_payment_method} does not support automatic renewal! This means you will need to click the link below to complete payment manually for every invoice we create for you. If you'd like your invoices to automatically renew, without your intervention, we suggest switching your default payment method to a Credit Card or a PayPal Subscription. Just click <a href="http://www.whmcs.com/clientarea.php?action=details">here</a> to change your default payment method for all invoices within your account. If you'd prefer to continue paying with {$invoice_payment_method}, simply click the link below to proceed.
{/if}
<p><strong>Invoice Details</strong></p>
<p>Invoice #{$invoice_num}<br />Default Payment Method: {$invoice_payment_method}<br />Amount Due: {$invoice_total}<br />Date Created: {$invoice_date_created}<br />Due Date: {$invoice_date_due}</p>
<p><strong>Invoice Items</strong></p>
<p>{$invoice_html_contents} <br /> ------------------------------------------------------</p>
<p>You can login to your client area to view and pay the invoice here: {$invoice_link}</p>
<p>{$signature}</p>

then it will send without generating any errors in the activity log.... but edit the template and the error returns.

there's something about that link that it doesn't like - remove it and the error goes away... also, for some reason, it removes the space after the closing </a>.

you could report it as a bug to WHMCS... or since you know it's working (e.g sending the email), you could ignore it.

I should also add that $ticket_department won't be available to the Invoice Created template... unless you've written a hook to add it.

Link to comment
Share on other sites

@brian!Good point regarding the $ticket_department variable... can't even remember how that got in there. Must have been a copy/paste error from way back when. I'll definitely get that fixed up. It was supposed to be: {if $invoice_payment_method eq 'PayPal'}

My other template exhibiting the same issue does *not* have conditionals with quotes in them, but it *does* have a link with double quotes. I wonder if perhaps switching all my URLs to single quotes will help. Worth a try! I'll update here with the results.

Edited by jas8522
Link to comment
Share on other sites

Fixed up the $invoice_payment_method variable and tried swapping quotes for single quotes. All of my quotes applied to URLs were changed back to double quotes upon save. But I was able to change all my conditional comparison strings to single quotes and have them stay that way. Sadly it didn't make a difference.

As @brian! hinted at, once I removed all links from within my conditional text, the syntax error stopped showing up in the logs. I'm going to submit this as a bug.

Link to comment
Share on other sites

Support set me straight. My variable checking model was the problem. We should not be using {if $variable} to check if it exists or is not empty. As suggested by WHMCS staff, we should instead be using {if isset($variable)} or this worked fine for me as well: {if !empty($variable)} 

Once I switched up the conditionals to check variables in that manner, all syntax errors stopped.

Link to comment
Share on other sites

3 hours ago, jas8522 said:

We should not be using {if $variable} to check if it exists or is not empty.

but in your sample code you weren't doing that. :?:

granted you were using a variable that wouldn't exist, but your code above checks if a variable equals something.... that's perfectly legitimate in the email templates and Smarty in general.

Link to comment
Share on other sites

13 hours ago, brian! said:

but in your sample code you weren't doing that. :?:

granted you were using a variable that wouldn't exist, but your code above checks if a variable equals something.... that's perfectly legitimate in the email templates and Smarty in general.

Huh, indeed. The other template I was working with did have those kinds of conditional checks. But that doesn't explain why this one didn't work. I've got URLs within the conditionals of my final (working) template as well and no issues now. Color me stumped.

Link to comment
Share on other sites

  • 2 months later...

Also just noticed this in my Activity Log as an error.

The unmodified default WHMCS email templates are giving errors such as:

Quote

Smarty Error: Syntax error in template "mailMessage:mailMessage:plaintext" on line 17 "{$signature}" unclosed {else} tag

As far as I can see, this error is caused/reported when a hyperlink is included within the body of an if/else statement. i.e. removing the hyperlink removes the error.........

Come on WHMCS...test your own default templates!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated