Add code to more than one template

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
hansbaars
New Member
New Member
Posts: 1
Joined: Wed Apr 10, 2024 3:03 pm

Add code to more than one template

Post by hansbaars »

Hi, I'm quite new with CMSMS and was wondering how to add PHP Code to Templates.
I know how to add it to a single template, but is it possible to add it to several Template at the same time?

Thanks in advance,

Best regards,
Ghans
User avatar
magallo
Dev Team Member
Dev Team Member
Posts: 109
Joined: Thu Mar 24, 2011 12:37 am

Re: Add code to more than one template

Post by magallo »

Hi, welcome to our forum!

Embedding PHP code within templates is generally not recommended due to security concerns and best practices, which encourage separating logic from presentation. However, if you need to include PHP code for specific functionality, you can enable PHP in templates where required.

To add PHP to a template in CMSMS, you must first ensure that the PHP code option is enabled in your system. Here's how to do it for individual templates:

Navigate to the CMSMS admin panel.
Go to Design > Templates.
Select the template where you want to include PHP.
Insert your PHP code within the Smarty {php}{/php} tags in the template.

Code: Select all

{php}
// Your PHP code here
echo 'Hello, this is PHP code!';
{/php}
Consider creating a User Defined Tag (UDT) that encapsulates your PHP code
1) Create a new UDT with your PHP code.
2) Use the tag {my_udt} in your templates

This method allows you to maintain and update your PHP code in one place and reuse it across multiple templates, enhancing maintainability and security.
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1630
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: Add code to more than one template

Post by DIGI3 »

Generally you wouldn't add PHP directly to your templates, as the power of CMSMS is in the Smarty templating engine - and most functions suitable for templates can be done in Smarty. If you do need PHP for specific functions, or when it's more efficient non-template logic, you can use User Define Tags as Magal mentioned.
Not getting the answer you need? CMSMS support options
Post Reply

Return to “CMSMS Core”