Loading tpl as content
-
Gibberish
Loading tpl as content
Just trying to find out if this is possible before I dive into it and try to create it.
Right now the templates get called from a database, I want them to get called from a folder.
So lets say a user chooses templateid 102, instead of grabbing the template from the template field I want it to grab it from a file such as templates/102.tpl. Which will have the exact same code as the template field had.
Anyone know if this is even possible?
Right now the templates get called from a database, I want them to get called from a folder.
So lets say a user chooses templateid 102, instead of grabbing the template from the template field I want it to grab it from a file such as templates/102.tpl. Which will have the exact same code as the template field had.
Anyone know if this is even possible?
-
calguy1000
- Support Guru

- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
Re: Loading tpl as content
Nope, don't think this is possible right now, everything is designed to come from the database, and not from the filesystem.
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.
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.
-
Gibberish
Re: Loading tpl as content
I know it's not possible by default but would this be possible with some modifications?
I guess my main question is will the CMS parse a file being loaded the same as it does to the database field?
I guess my main question is will the CMS parse a file being loaded the same as it does to the database field?
-
calguy1000
- Support Guru

- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
Re: Loading tpl as content
if the templates were stored in a file, and the proper function were called in the core, then, yes, it would work, however there have been design decisions to keep the templates and content, and blobs in the database so don't know if you'd find anybody willing to make those changes.
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.
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.
Re: Loading tpl as content
Assuming that 102.tpl was stored in tmp/templates, then in theory you should be able to change in index.php
to
I've never tried this before, but there is no reason why it can't. It's just using standard smarty hooks and plugins anyway...
Code: Select all
$html = $smarty->fetch('template:'.$pageinfo->template_id) . "\n";Code: Select all
$html = $smarty->fetch($pageinfo->template_id . '.tpl') . "\n";-
Gibberish
Re: Loading tpl as content
I havent spent more then 10 minutes on it but chaning the $html value produced a 404 error.
/edit/
here is the fix for the index.php
/edit/
Changing this line on content.function.php worked though.
to
assuming the temp.tpl is in the root of the cms. I will later use the id to call the tpl, this was just to see if it would work.
Thanks for the help.
/edit/
here is the fix for the index.php
Code: Select all
$html = file($pageinfo->template_id.".tpl");Changing this line on content.function.php worked though.
Code: Select all
$tpl_source = $templateobj->content;Code: Select all
$tpl_source = file("temp.tpl");Thanks for the help.
Last edited by Gibberish on Tue Dec 20, 2005 6:45 pm, edited 1 time in total.
Re: Loading tpl as content
I was thinking that you were using a template as a template, not content. (say that 5 times fast).
Anyway, same rules apply, just need to make the change in a different place to affect the content instead. In plugins/function.content.php, change
to
Though, keep in mind that any templates with multiple content blocks will have their contents repeated. This also assumes that the 102.tpl is in tmp/templates.
Anyway, same rules apply, just need to make the change in a different place to affect the content instead. In plugins/function.content.php, change
Code: Select all
$oldvalue = $smarty->caching;
$smarty->caching = $pageinfo->content_cachable;
$result = $smarty->fetch(str_replace(' ', '_', 'content:' . (isset($params['block'])?$params['block']:'content_en')), '', $pageinfo->content_id);
$smarty->caching = $oldvalue;
Code: Select all
$result = $smarty->fetch($pageinfo->content_id . '.tpl');
-
Gibberish
Re: Loading tpl as content
Getting back into this now that the holidays are passed and I am running into a few problems.
I tried changing the code in the index.php and I get nothing but errors.
If I replace:
with it prints out the file in the browser as if the file were open in notepad.
If I use this code I get "Not Found". The file is in the root and $siteinfo->site_template echos '101'.
I tried doing your suggestion in plugins/function.content.php. That seems to redo the template for evey single content block. So I end up getting about 4 headers on the site.
I am trying to write the template_content that is called from the templates table with the contents of a tpl file. So instead of loading from the table field it loads from a specific file.
Thanks for the help so far. I have found tweaking the CMS to my needs somewhat simple with the well layed out file strucutre and comments in the functions.
I tried changing the code in the index.php and I get nothing but errors.
If I replace:
Code: Select all
$html = $smarty->fetch($pageinfo->template_id . '.tpl') . "\n";Code: Select all
$html = $smarty->fetch(implode('', file("101.tpl"))) . "\n";If I use this code
Code: Select all
$html = $smarty->fetch($siteinfo->site_template.".tpl") . "\n";I tried doing your suggestion in plugins/function.content.php. That seems to redo the template for evey single content block. So I end up getting about 4 headers on the site.
I am trying to write the template_content that is called from the templates table with the contents of a tpl file. So instead of loading from the table field it loads from a specific file.
Thanks for the help so far. I have found tweaking the CMS to my needs somewhat simple with the well layed out file strucutre and comments in the functions.

