Jump to content

Allow Smarty PHP tags not Recommended


web2008

Recommended Posts

{php} in smarty has been pretty much taboo for a while now ;) . Since v3, smarty has disabled this by default, and wisely so.

 

As sentq mentioned, you can use an action hook, pass this to the smarty system itself. It's really going to be hard to provide specifics unless you tell us what you're looking for here. I mean

include ("file.php")

 

is pretty generic, you know?

 

Take a look at Templates and Custom PHP logic or Template:Hook:ClientAreaPageActions . These should at least give you an idea on how to do this.

Link to comment
Share on other sites

What I was looking for was something that replaced

 

{php}

include('./file.php');

{/php}

 

This seems to work perfect, regardless of the code in "file.php" when Allow Smarty PHP tags is enabled.

 

But if I have to pay attention to what the code is in the php file, then it becomes a little more complex, or have I misunderstood?

 

I can not post the code for generating the password, as this is something I've bought, but what about the following example?

 

Please see the attachment!

 

This code works fine with the "include('./file.php');" in a .tpl file.

file.zip

Link to comment
Share on other sites

I realize that I have to think, but I'm not just talking about my specific php script, but the correct way to do this.

 

Using Smarty PHP tags is the very simple and as I understand it now, after several answers, the code in the php file must be converted to a ActionHook,

so I can display the result in the .tpl file. Is this correct or can the code in the php file still be used as it is?

 

Sorry all stupid questions, but everything must be learned!

Link to comment
Share on other sites

What I was looking for was something that replaced

This seems to work perfect, regardless of the code in "file.php" when Allow Smarty PHP tags is enabled.

But if I have to pay attention to what the code is in the php file, then it becomes a little more complex, or have I misunderstood?

not only to what the code is, but where it's going to be used... e.g if it's to be used in the admin area, you need an admin action hook, and the opposite for the client area... and if it's only needed on a specific page, there may be a specific hook to use... context is important!

 

I can not post the code for generating the password, as this is something I've bought, but what about the following example?

This code works fine with the "include('./file.php');" in a .tpl file.

I looked at the code and my first thought was that it could probably be re-written in Smarty without the need for an action hook, but as it's only an example, i'm not going to waste time testing that. :)

 

there was an admin password hook posted in the thread below - but it's using javascript and probably not the best example if you wanted to convert your code - which I assume is all PHP.

 

https://forum.whmcs.com/showthread.php?91219-Free-Hook-Module-Random-Password-generator-for-admins&p=449690#post449690

 

Using Smarty PHP tags is the very simple and as I understand it now, after several answers, the code in the php file must be converted to a ActionHook,

AFAIK, using {php} tags in Smarty has always been considered potentially dangerous and frowned upon - it is today, and was when you bought your password code... the only difference is that v6 & v7 had warning messages about it's use - they would have done that because the option was removed from Smarty and, ultimately, will be removed from WHMCS.

 

when I first bought WHMCS and started using Smarty, every reference I found always said to avoid using {php} tags - it's a quick solution, but discouraged.

 

I don't think that it's any more dangerous to use your code today that it was when you bought it - but you now know that there is a potential risk in using it (which I assume you were unaware of when you initially bought it)... certainly, as the guys have said, it will HAVE to be converted to an action hook at some point if you want to continue to use the feature(s) it provides.

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