Page 1 of 1

how to get the HTML result of a global content block

Posted: Mon Sep 29, 2008 8:19 am
by maxwell44
Hi,

I need to get the data from the cms to put it into a variable and display it afterward.

I am using ajax to change dynamicaly the content of a div (using innerHTML).
into this div I want to load a page which exists into the CMS.

for now I am doing that:

Code: Select all


include_once(dirname(__FILE__).'/../include.php');
include_once(dirname(__FILE__).'/../lib/config.functions.php');
include_once(dirname(__FILE__).'/../lib/adodb.functions.php');
require_once(dirname(__FILE__).'/../lib/classes/class.global.inc.php');


$gCms = new CmsObject();
$db =& $gCms->GetDb();

$sql = "SELECT `content_id` FROM `cms_content` WHERE `content_alias` LIKE ?";
$result = $db->GetRow($sql, array( 'get-quote' ));

if (isset($result['content_id']) && !is_null($result['content_id']) &&!empty($result['content_id'])){
	$get_quote_page_id = $result['content_id'];

	$sql = "SELECT `content` FROM `cms_content_props` WHERE `prop_name` LIKE ? AND `content_id` LIKE ?";
	$result = $db->GetRow($sql, array( 'content_en', $get_quote_page_id ));

	if (isset($result['content']) && !is_null($result['content']) &&!empty($result['content'])){
		echo $result['content'];
	}
}
else{
	echo "Page not found";
}
The problem is that into this page I have a global content block, and into this global content block I have a tag which is setting some smarty variable which are interpreted into the global content block. I know it's a little bit complex to explain.

well, when I display the page, instead to have the HTML code of the global content block I have :

{global_content name='captcha'} in plain text.


so ... I decide to replace this tag (if I find it) with the value of the content block, and my code become :

Code: Select all

<?php

include_once(dirname(__FILE__).'/../include.php');
include_once(dirname(__FILE__).'/../lib/config.functions.php');
include_once(dirname(__FILE__).'/../lib/adodb.functions.php');
require_once(dirname(__FILE__).'/../lib/classes/class.global.inc.php');
require_once(dirname(__FILE__).'/../lib/classes/class.content.inc.php');
require_once(dirname(__FILE__).'/../lib/classes/class.contentoperations.inc.php');
require_once(dirname(__FILE__).'/../lib/classes/class.globalcontentoperations.inc.php');

$gCms = new CmsObject();
$db =& $gCms->GetDb();

$sql = "SELECT `content_id` FROM `cms_content` WHERE `content_alias` LIKE ?";
$result = $db->GetRow($sql, array( 'get-quote' ));

if (isset($result['content_id']) && !is_null($result['content_id']) &&!empty($result['content_id'])){
	$get_quote_page_id = $result['content_id'];

	$sql = "SELECT `content` FROM `cms_content_props` WHERE `prop_name` LIKE ? AND `content_id` LIKE ?";
	$result = $db->GetRow($sql, array( 'content_en', $get_quote_page_id ));

	if (isset($result['content']) && !is_null($result['content']) &&!empty($result['content'])){
		//echo '<__script__>document.write('.$result['content'].');</__script>';

		
		############################# captcha ################################
		$gco = new GlobalContentOperations();
		$gc_content = $gco->LoadHtmlBlobByName('captcha');
		
		# into this content there is one content block.
		$result['content'] = str_replace("{global_content name='captcha'}", $gc_content['content'], $result['content']);
		echo $result['content'];
	}
}
?>
But the tag into the content block are not interpreted .... so now I have to inlcude the PHP file which correspond to the tag... etc.

I want to know if there is a function into the CMS which allow the developer to get the HTML result of a global content block ?
If yes which one ? if no how can I do ?

Thanks a lot

Re: how to get the HTML result of a global content block

Posted: Mon Sep 29, 2008 9:16 am
by scooper
It's not going to be beautiful but you can process a global content block from inside a UDT usingĀ  Calguys trick outlined here:

http://forum.cmsmadesimple.org/index.ph ... 381.0.html

Re: how to get the HTML result of a global content block

Posted: Mon Sep 29, 2008 12:48 pm
by duclet
I am not sure if this is completely the case, but as I was working on my module yesterday, it seems like if I use "assign" in the tag, Smarty automatically assign the output to the variable even though I did not specify it in my code to do so. So, just try {global_content name='your block' assign='some_variable'}