Page 1 of 1

Get node content in menu module

Posted: Thu Sep 18, 2008 11:47 pm
by gilescambray
I am trying to create a menu in which some of the content blocks can be rendered.
Eg http://lunariot.gilescambray.com/music/test-album/

The album cover on the right is it's own content block, yet I would like it to appear on the left, which is a menu using the menu manager module.

In advance, thanks

Re: Get node content in menu module

Posted: Fri Sep 19, 2008 12:59 am
by nhaack
Hey gilescambray,

I had exactly the same problem. However, the menu manager couldn't help... or at least I couldn't figure out how to do it. But I guess as a Menu Manager it isn't build for such tasks.

I wrote a little UDT that does the job for me. You might want to check it out.

Code: Select all



global $gCms;
global $smarty;

$db = &$gCms->db;

// make Query
$q = "SELECT 
	content_name, 
	content_alias, 
	show_in_menu, 
	content,
	active, 
	".cms_db_prefix()."content_props.content_id, 
	prop_name

	FROM 
	".cms_db_prefix()."content, ".cms_db_prefix()."content_props

	WHERE 
	".cms_db_prefix()."content.content_id = ".cms_db_prefix()."content_props.content_id
	AND active = 1
	AND show_in_menu = 1
	AND parent_id = $params[parent_id]
	AND prop_name = '$params[content]'
	ORDER BY content_id
		";
		
$dbresult = $db->Execute( $q );

if( !$dbresult )
{
    echo 'DB error: '. $db->ErrorMsg()."<br/>";
}


	$super_navi = array();

while ($dbresult && $dbcontent = $dbresult->FetchRow())
{ 
	$item = new StdClass;
	
	$item->alias = $dbcontent[content_alias];
	$item->name =  $dbcontent[content_name];
	$item->content =  $dbcontent[content];
	$item->id =  $dbcontent[content_id];

	$super_navi[] = $item;
}

	$smarty = &$gCms->GetSmarty();
	$smarty->assign(super_navi, $super_navi);
	
	return;
		
Assuming that the UDT is stored with the name "supernavi", you can call it like this in the template:

Code: Select all


{supernavi content="content_en" parent_id=-1}

- or -

{supernavi content="album_cover" parent_id=45}

the parameter content="xxx" is used to identify the content-block you want to use. parent_id=123 identifies the parent of the pages you want to display.

And now it is pretty similar to the menu manager. To, eg show all items do something like this in your template after calling supernavi as previously described:

Code: Select all


{foreach from=$super_navi item=album}

{$album->alias}
{$album->name}
{$album->content}
{$album->id}

{/foreach}

Hopefully this bit of code can be a help for you. Please keep in mind that only displays direct children, it doesn't go trough more than one hierarchy level. Let me know how it worked for you.

Best
Nils

Re: Get node content in menu module

Posted: Mon Sep 22, 2008 9:07 pm
by gilescambray
Nils
Apologies for my apparent allusiveness over the past couple of days - I have just tried this and it works a treat. Many thanks for your help - I owe you one! :)
Giles