Fr3DBr Posted April 22, 2016 Share Posted April 22, 2016 (edited) 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 April 22, 2016 by Fr3DBr 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 22, 2016 Share Posted April 22, 2016 (edited) 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 April 22, 2016 by brian! 0 Quote Link to comment Share on other sites More sharing options...
Fr3DBr Posted April 22, 2016 Author Share Posted April 22, 2016 why is there a double opening bracket here at the end of the {php} line ? {{/php} The issue is not the braket, since this one is for the php if condition... 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 22, 2016 Share Posted April 22, 2016 The issue is not the braket, since this one is for the php if condition... I know - I modified my answer before your reply! 0 Quote Link to comment Share on other sites More sharing options...
Fr3DBr Posted April 22, 2016 Author Share Posted April 22, 2016 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 ? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 22, 2016 Share Posted April 22, 2016 can you use replace them back? {$variable|replace:'>':'>'|replace:'<':'<'} 0 Quote Link to comment Share on other sites More sharing options...
Fr3DBr Posted April 22, 2016 Author Share Posted April 22, 2016 can you use replace them back? {$variable|replace:'>':'>'|replace:'<':'<'} How would I apply that around the php block I've built ? What I mean is that this happens inside {php}{/php} block, not in variables. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 22, 2016 Share Posted April 22, 2016 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. 0 Quote Link to comment Share on other sites More sharing options...
Fr3DBr Posted April 22, 2016 Author Share Posted April 22, 2016 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. 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. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 22, 2016 Share Posted April 22, 2016 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. 0 Quote Link to comment Share on other sites More sharing options...
Fr3DBr Posted April 22, 2016 Author Share Posted April 22, 2016 (edited) 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... (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 April 22, 2016 by Fr3DBr 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 22, 2016 Share Posted April 22, 2016 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... (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. 0 Quote Link to comment Share on other sites More sharing options...
Fr3DBr Posted April 22, 2016 Author Share Posted April 22, 2016 (edited) 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 April 22, 2016 by Fr3DBr 0 Quote Link to comment Share on other sites More sharing options...
Fr3DBr Posted April 22, 2016 Author Share Posted April 22, 2016 * delete please * 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 22, 2016 Share Posted April 22, 2016 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! 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... 0 Quote Link to comment Share on other sites More sharing options...
Fr3DBr Posted April 22, 2016 Author Share Posted April 22, 2016 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! 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). 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 22, 2016 Share Posted April 22, 2016 0 Quote Link to comment Share on other sites More sharing options...
Fr3DBr Posted April 22, 2016 Author Share Posted April 22, 2016 Jesus christ, this... Is this the magic button ?! It worked fine after I've used it, lol. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.