Page 1 of 1
Loading tpl as content
Posted: Tue Dec 20, 2005 5:11 pm
by Gibberish
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?
Re: Loading tpl as content
Posted: Tue Dec 20, 2005 5:15 pm
by calguy1000
Nope, don't think this is possible right now, everything is designed to come from the database, and not from the filesystem.
Re: Loading tpl as content
Posted: Tue Dec 20, 2005 5:23 pm
by Gibberish
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?
Re: Loading tpl as content
Posted: Tue Dec 20, 2005 5:27 pm
by calguy1000
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.
Re: Loading tpl as content
Posted: Tue Dec 20, 2005 6:06 pm
by Ted
Assuming that 102.tpl was stored in tmp/templates, then in theory you should be able to change in index.php
Code: Select all
$html = $smarty->fetch('template:'.$pageinfo->template_id) . "\n";
to
Code: Select all
$html = $smarty->fetch($pageinfo->template_id . '.tpl') . "\n";
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...
Re: Loading tpl as content
Posted: Tue Dec 20, 2005 6:20 pm
by Gibberish
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
Code: Select all
$html = file($pageinfo->template_id.".tpl");
/edit/
Changing this line on content.function.php worked though.
Code: Select all
$tpl_source = $templateobj->content;
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.
Re: Loading tpl as content
Posted: Tue Dec 20, 2005 7:58 pm
by Ted
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
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;
to
Code: Select all
$result = $smarty->fetch($pageinfo->content_id . '.tpl');
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.
Re: Loading tpl as content
Posted: Tue Dec 20, 2005 8:42 pm
by Gibberish
awesome thanks.
Re: Loading tpl as content
Posted: Tue Jan 03, 2006 6:27 am
by Gibberish
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:
Code: Select all
$html = $smarty->fetch($pageinfo->template_id . '.tpl') . "\n";
with
Code: Select all
$html = $smarty->fetch(implode('', file("101.tpl"))) . "\n";
it prints out the file in the browser as if the file were open in notepad.
If I use this code
Code: Select all
$html = $smarty->fetch($siteinfo->site_template.".tpl") . "\n";
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.