How to include a *.tpl file in my template???

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
jmansa
Forum Members
Forum Members
Posts: 126
Joined: Thu Oct 19, 2006 2:46 pm

How to include a *.tpl file in my template???

Post by jmansa »

Is it possible to include a *.tpl file inside my template.html, and if yes... How?

I have tryid this:
{include file="/templates/sommerbar.tpl"}

But get this error:
string(65) "Smarty error: unable to read resource: "/templates/sommerbar.tpl""

Hope somebody can help!!!
RonnyK
Support Guru
Support Guru
Posts: 4962
Joined: Wed Oct 25, 2006 8:29 pm
Location: Raalte, the Netherlands

Re: How to include a *.tpl file in my template???

Post by RonnyK »

Did you try without the leading "/" as that starts at the root, instead of the CMSMS-root, so you might try with a relative path....

Ronny
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: How to include a *.tpl file in my template???

Post by calguy1000 »

Well, 1:  CMS doesn't have a templates directory,  so you'd have to create one
then 2:  have you tried (after creating the directory above) calling {include file="something.tpl"}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
JeremyBASS

Re: How to include a *.tpl file in my template???

Post by JeremyBASS »

Was there any fix to this? I tryed it too and only got string(54) "Smarty error: unable to read resource: "Test_Page.tpl"" useing {include file='Test_Page.tpl'} in the templates.  The folld which is located in the root named templates.  Would love to see this work.

jeremyBass
Last edited by JeremyBASS on Wed Jun 04, 2008 4:16 am, edited 1 time in total.
cyberman

Re: How to include a *.tpl file in my template???

Post by cyberman »

Hi Jeremy,
JeremyBASS wrote: The folld which is located in the root named templates.
Like calguy said
calguy1000 wrote: Well, 1:  CMS doesn't have a templates directory,  so you'd have to create one
/tmp/templates is not the template folder, which Smarty means

http://www.smarty.net/manual/en/api.var ... mplate.dir

You can try it to assign via user defined tag (before your include call)

Code: Select all

global $gCms;
$smarty->template_dir = $config['root_path'].'/tmp/templates';
JeremyBASS

Re: How to include a *.tpl file in my template???

Post by JeremyBASS »

Just FYI No,  {include file='Test_Page.tpl'} does  works, I had to move the templates folder to /tmp/templates on the root... so yes /tmp/templates isnot the template folder, which Smarty means.

Thanks for the help... :) have a great one...
Deykun
New Member
New Member
Posts: 5
Joined: Thu Jun 22, 2017 5:03 pm

Re: How to include a *.tpl file in my template???

Post by Deykun »

A response from the far future. Add plugins/function.get_tpl.php:

Code: Select all

<?php
//opcache_reset();

function smarty_function_get_tpl($params, $smarty)
{
  // empty($params['name']
  $config = cmsms()->GetConfig();

  $smarty->display($config['root_path'] . '\your_path\\' . $params['path']);
}

?>
Use:

Code: Select all

{get_tpl path=”sections\\SectionFormProduct.tpl”}
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1945
Joined: Mon Jan 29, 2007 4:47 pm

Re: How to include a *.tpl file in my template???

Post by Jo Morg »

For the sake of clarity:
  • when this thread started CMSMS had a different and more limited mechanism to handle with templates in files; This is no longer the case;
  • using an UDT as suggested by Deykun is a valid possibility, but not needed nor recommended;
  • the correct way to use tpl files is as follows:
    1. use assets\templates as the root for your templates organization;
    2. use any hierarchy of folders you wish, say add a common folder for example;
    3. if you added a top_logic.tpl template file inside the common folder, then you can call from any of your other templates:

      Code: Select all

      {include "common/top_logic.tpl"}
As simple as that! HTH!
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Post Reply

Return to “Developers Discussion”