how to get the HTML result of a global content block

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Locked
maxwell44
New Member
New Member
Posts: 3
Joined: Mon Sep 29, 2008 8:04 am

how to get the HTML result of a global content block

Post 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
scooper
Forum Members
Forum Members
Posts: 242
Joined: Fri Dec 09, 2005 12:36 pm
Location: Marlow, UK

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

Post 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
User avatar
duclet
Forum Members
Forum Members
Posts: 187
Joined: Fri Jun 23, 2006 12:55 pm

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

Post 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'}
Locked

Return to “Developers Discussion”