Loading tpl as content

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.
Locked
Gibberish

Loading tpl as content

Post 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?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Loading tpl as content

Post by calguy1000 »

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.
Gibberish

Re: Loading tpl as content

Post 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?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Loading tpl as content

Post 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.
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.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

Re: Loading tpl as content

Post 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...
Gibberish

Re: Loading tpl as content

Post 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

Code: Select all

$tpl_source = file("temp.tpl");
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.
Last edited by Gibberish on Tue Dec 20, 2005 6:45 pm, edited 1 time in total.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

Re: Loading tpl as content

Post 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.
Gibberish

Re: Loading tpl as content

Post by Gibberish »

awesome thanks.
Gibberish

Re: Loading tpl as content

Post 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.
Locked

Return to “CMSMS Core”