Jump to content

Smarty Issue (PHP Conversion Error)


Fr3DBr

Recommended Posts

Hi guys.

 

Why when working in an e-mail template, this doesn't works:

 

{php}if (strlen($this->_tpl_vars['service_assigned_ips']) > 0) {{/php}--

IP address allocation (Extra Addresses):

{$service_assigned_ips}

--{php}}{/php}

 

I am asking, because in the generated php code (at templates_c folder) whmcs is converting the:

 

> character (yes >) into > and this is corrupting the php code. Any ideas here ?

Edited by Fr3DBr
Link to comment
Share on other sites

you can use PHP modifiers in Smarty...

 

{assign var="strlen" value=$service_assigned_ips|count_characters}
{if strlen > 0}
do something
{/if}

you might even be able to drop the assign and use it directly in the {if} statement depending on your version of Smarty.

Edited by brian!
Link to comment
Share on other sites

you can use PHP modifiers in Smarty...

 

{assign var="strlen" value=$service_assigned_ips|count_characters}
{if strlen > 0}
do something
{/if}

you might even be able to drop the assign and use it directly in the {if} statement depending on your version of Smarty.

 

Yes, I understand, the problem is that somehow the whmcs implementation of smarty is converting characters (formatting them) for html output and that is breaking the php compiled template in templates_c folder, like I've said above, it converts the character > to > and the character < to < any way to avoid this behavior ?

Link to comment
Share on other sites

Hi,

 

first of all, I wouldn't use {php} in email templates unless you have to - if you can do it purely in Smarty, that's the way to go... so, if all you want to do is check a length of a variable and do something based on that length, then you can do that in Smarty (as shown above).

 

secondly, if > is causing an issue, then you could use gt in Smarty to bypass the issue.

 

{if strlen gt 0}

 

thirdly, there was an issue in previous versions, when entering code into the template would convert < > on saving - if memory serves, the way around it was "Edit HTML Source" button (far right icon when editing the template)... or if you're familiar with the database, to edit the template directly in there - that way you can bypass WHMCS mistakenly converting those characters. :idea:

Link to comment
Share on other sites

Hi,

 

first of all, I wouldn't use {php} in email templates unless you have to - if you can do it purely in Smarty, that's the way to go... so, if all you want to do is check a length of a variable and do something based on that length, then you can do that in Smarty (as shown above).

 

secondly, if > is causing an issue, then you could use gt in Smarty to bypass the issue.

 

{if strlen gt 0}

 

thirdly, there was an issue in previous versions, when entering code into the template would convert < > on saving - if memory serves, the way around it was "Edit HTML Source" button (far right icon when editing the template)... or if you're familiar with the database, to edit the template directly in there - that way you can bypass WHMCS mistakenly converting those characters. :idea:

 

I get it too, the problem is that Whmcs (v5), as we couldn't migrate to (v6) yet, doesn't like us to use that specific variable, when we do it, it ends up not recognising it, hence why we decided to use php, your example of using modifiers in smarty is nice, just that for some reason "this variable" is not working properly, resulting in compilation errors.

Link to comment
Share on other sites

I get it too, the problem is that Whmcs (v5), as we couldn't migrate to (v6) yet, doesn't like us to use that specific variable, when we do it, it ends up not recognising it, hence why we decided to use php, your example of using modifiers in smarty is nice, just that for some reason "this variable" is not working properly, resulting in compilation errors.

then the next obvious question to ask is whether {$service_assigned_ips} is available to this particular email template - not all mergefields are available to all templates - some are only used in certain types.

 

the quick way to check would be to see if it's included in the mergefield table at the bottom of the page - if it isn't, then you can't use it; if it is, then we might get somewhere.

 

if it is mentioned, what's it's value when you just use {$service_assigned_ips} in the email - is it blank ?

btw - which email template are you trying this in ?

 

if it's not available, then you might need to write an action hook to make the variable available to the email template.

Link to comment
Share on other sites

then the next obvious question to ask is whether {$service_assigned_ips} is available to this particular email template - not all mergefields are available to all templates - some are only used in certain types.

 

the quick way to check would be to see if it's included in the mergefield table at the bottom of the page - if it isn't, then you can't use it; if it is, then we might get somewhere.

 

if it is mentioned, what's it's value when you just use {$service_assigned_ips} in the email - is it blank ?

btw - which email template are you trying this in ?

 

if it's not available, then you might need to write an action hook to make the variable available to the email template.

 

It is available, because this e-mail template is used when Dedicated Servers are provisioned, so yes, it is part of the merge fields. And no, it is not blank, I can see all the IPs there.

 

Regarding the issue I've told you, a php compilation error happens, even if the variable wasn't available, since it try to grab it from the smarty array, no error had to happen, the problem is that this variable is not properly translated into the php get smarty variable block... :P (If you check the generated code in templates_c you'll notice what I mean).

 

The e-mail template is : Dedicated/VPS Server Welcome Email

Edited by Fr3DBr
Link to comment
Share on other sites

It is available, because this e-mail template is used when Dedicated Servers are provisioned, so yes, it is part of the merge fields. And no, it is not blank, I can see all the IPs there.

oh if it exists, then Smarty should be able to use an IF statement around it...

 

{if $service_assigned_ips neq ''}--
IP address allocation (Extra Addresses):
{$service_assigned_ips}--{/if}

so the above is just Smarty - don't wrap it in {php} tags!!! :)

 

it checks to see if {$service_assigned_ips} is empty - if it isn't (i.e it contains IP addresses), it will output the message and display the value of {$service_assigned_ips}; if it it empty, it will not output any message.

 

Regarding the issue I've told you, a php compilation error happens, even if the variable wasn't available, since it try to grab it from the smarty array, no error had to happen, the problem is that this variable is not properly translated into the php get smarty variable block... :P (If you check the generated code in templates_c you'll notice what I mean).

I get it, I just don't think you can do that - it looks like you're trying code that might work in a client area template, within an email template - and they are two totally different beasts.

 

anyway, remove your {php} code and try the Smarty code instead.

Link to comment
Share on other sites

The smarty code you've used is exactly what I've used before (in my first attempt), it doesn't works, and causes a PHP Compilation error in the smarty generated php template file at templates_c folder, in fact what happens is that it doesn't translate that if statement with neq check into php code... (it is not present in the generated file).

 

Or if it does, it happens in the wrong way look:

 

<br /><br /><?php if ($this->_tpl_vars['service_assigned_ips'] ne ''): ?>--<br />IP address allocation (Extra Addresses):<br /><br /><?php echo $this->_tpl_vars['service_assigned_ips']; ?>

 

Did you notice the : right after the ne '') ? This is incorrect... :(

Edited by Fr3DBr
Link to comment
Share on other sites

I just tried the smarty code in a v5.3.14 dev installation and it worked fine (email sent) - added the code after the signature... output needs tweaking, but the Smarty code works! :idea:

 

uZGfuHA.png

 

this is what the html source looks like from the popup..

 

<p>=============================</p>
<p>{$signature}<br /> {if $service_assigned_ips neq ''}-- IP address allocation (Extra Addresses): {$service_assigned_ips}--{/if}</p>

if you just paste the code into the template, then that's prone to errors - add it using the html popup window, and it should be fine...

Link to comment
Share on other sites

I just tried the smarty code in a v5.3.14 dev installation and it worked fine (email sent) - added the code after the signature... output needs tweaking, but the Smarty code works! :idea:

 

uZGfuHA.png

 

this is what the html source looks like from the popup..

 

<p>=============================</p>
<p>{$signature}<br /> {if $service_assigned_ips neq ''}-- IP address allocation (Extra Addresses): {$service_assigned_ips}--{/if}</p>

if you just paste the code into the template, then that's prone to errors - add it using the html popup window, and it should be fine...

 

Do you mind telling me which popup window is this ? Because here, I just have an inline editing tool (like a blog for example).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • 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