Jump to content

Allow PHP scripts in smarty template


John-nl

Recommended Posts

I wan't to allow php scripts within a smarty template with {php} //my php code {/php} tags.

When i use  these tags get this smarty error: {php}{/php} tags not allowed. Use SmartyBC to enable them 

I can see the SmartyBC class in the /vendor/smarty folder and have looked into the three smarty config files within the /config folder, But i cannot figure out how to enable SmartBC in Prestashop 1.7.

 

Thanks

Link to comment
Share on other sites

You should not use PHP in Smarty. Prestashop pages are split between a controller, several models and several views. PHP stuff belongs in the controller and Smarty/twig stuff in the view. Hacking a way around it is going to cause more frustration in the end.

Continue in the controller if you can and use an override if you are lucky enough to be using the last working version of Prestashop.

Link to comment
Share on other sites

PHP was allowed in very old Smarty versions. It is not allowed in the version that Prestashop uses.

Smarty code language is quite flexible and you can do quite a bit of processing with it. But things like database access you need to arrange in the code that calls the template.

Link to comment
Share on other sites

Thanks for you're answer

I have changed new Smarty() to newSmartyBC()  on line 34 in config/smarty.config.inc.php

But still receive the message {php}{/php} tags not allowed. Use SmartyBC to enable them

Any suggestions?

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...