Author Topic: Remove ccmsContent function call from templates  (Read 320 times)

youcantryreachingme

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +1/-0
    • View Profile
Remove ccmsContent function call from templates
« on: December 18, 2009, 02:00:41 PM »
Just wondering why the function call ccmsContent() is in the templates? Would it make sense to convert this to a template variable?

For example, in index.php, have:

Code: [Select]
$ccms['pagecontent'] = ccmsContent();
and in the template, replace:

Code: [Select]
ccmsContent();
with:

Code: [Select]
{%pagecontent%}
I'll give it a go..

youcantryreachingme

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +1/-0
    • View Profile
Re: Remove ccmsContent function call from templates
« Reply #1 on: December 18, 2009, 02:11:08 PM »
One more step. Find the full function definition at about line 111 in /lib/sitemap.php and replace it with the following:

Code: [Select]
function ccmsContent() {
global $link, $ccms, $cfg;
ob_start(); // start buffer
if($ccms['published']=='Y') {
include_once(dirname(dirname(__FILE__)). "/content/".$ccms['urlpage'].".php");
} elseif($ccms['published']=='N') {
include_once(dirname(dirname(__FILE__)). "/content/403.php");
}
$content = ob_get_contents(); // assign buffer contents to variable
ob_end_clean(); // end buffer and remove buffer contents
return $content;
}

Xander

  • Developer
  • Administrator
  • Full Member
  • *****
  • Posts: 232
  • Karma: +5/-0
    • View Profile
    • CompactCMS.nl
Re: Remove ccmsContent function call from templates
« Reply #2 on: December 20, 2009, 03:08:54 PM »
Ha! Who would have figured...

I assumed - I honestly admit - that due to the PHP coding and its parsing it was necessary to keep this line as PHP. But your method using output buffering works very well (also with the guestbook, lightbox and contact form). So to answer your original question: based on your information it is absolutely useful to convert the PHP line to a template variable. So in a next release I'll adopt this change for sure.

Don't forget to also change the 404 content variable


$ccms
['content']
	
file_get_contents(dirname(dirname(__FILE__)). "/content/404.php");


The adopted code now looks like the one below:


	
	
// Parse contents
	
	
function 
ccmsContent() {
	
	
	
global 
$link$ccms$cfg;
	
	
	
ob_start();
	
	
	
	
if(
$ccms['published']=='Y') {
	
	
	
	
	
include_once(
dirname(dirname(__FILE__)). "/content/".$ccms['urlpage'].".php");
	
	
	
	
} elseif(
$ccms['published']=='N') {
	
	
	
	
	
include_once(
dirname(dirname(__FILE__)). "/content/403.php");
	
	
	
	
}
	
	
	
	
$content ob_get_contents();
	
	
	
ob_end_clean();
	
	
	
return 
$content;
	
	
}
	
	
$ccms['content']
	
ccmsContent();


Thanks so much for the contribution :). This actually makes it possible to perhaps make the template file itself editable through the administration as well (admin only function). An idea that was suggested which I considered irrelevant because of the one remaining PHP line..

Cheers!
Xander.
Don't ever hold back your suggestions. Help me either to improve CompactCMS or spread the word about it on sites such as Twitter, Digg, StumbleUpon, etc :). Thanks!