By dgtlmoon on
Ok heres what ive managed to achieve, it may be useful to you
- Define a view that filters nodes based on taxonomy terms
- Have that view render the related nodes via Smarty template engine
- have the flexinode's also available to smarty but use proper naming instead of field ID's
I created a flexinode called "Human or Person" and a view called "About our team" which is a view containg a list of nodes that are related by taxonomy.
The flexinode template is called flexinode-HumanOrPerson.tpl
The view template is called view-AboutOurTeam.tpl
In my bluemarine_smarty theme folder i create a "smartytemplate.php" and added the following
<?php
// all views go via here..
function smarty_views_view($view, $type, $nodes) {
$i=0;
foreach($nodes as $node) {
$result = db_query("select flexinode_data.*, flexinode_field.* from flexinode_data
left join flexinode_field on flexinode_data.field_id= flexinode_field.field_id where nid=%d",$node->nid);
if(db_num_rows($result)) {
while( $dbobj = db_fetch_object($result) )
$viewobject[$i]["flexinode"][preg_replace("/[^\w\d]/","",ucwords($dbobj->label))]=$dbobj; // Ask for it by array offset
$i++;
}
}
// view filenames are view-AboutOurTeam.tpl etc in current theme path
$viewfilename="view-".preg_replace("/[^\w\d]/","",ucwords($view->name)).".tpl";
$filename="/usr/share/drupal/".path_to_theme()."/".$viewfilename;
// got a template for this view? make it Smarty
if (file_exists($filename) ) {
$content="<!--- _views_view: $viewfilename --->\n";
$smarty=new SmartyTemplate;
$smarty->assign('viewobject',$viewobject);
$content.=$smarty->fetch($filename);
} else {
$content="<!--- not found _views_view: $viewfilename --->\n";
}
// print_r($viewobject);
return $content;
}
// hook to watch for a flexinode being viewed and outsource its templating abilities like smart_views_view()
function bluemarine_smarty_node($node, $teaser = FALSE, $page = FALSE) {
if(eregi("^flexinode",$node->type)) {
$result=db_query("select flexinode_type.*,flexinode_data.*, flexinode_field.* from flexinode_data
left join flexinode_field on flexinode_data.field_id= flexinode_field.field_id
left join flexinode_type on flexinode_field.ctype_id=flexinode_type.ctype_id where nid=%d",$node->nid);
// load the flexinode parts into an array ready for Smarty
while($dbobj = db_fetch_object($result)) {
if(!$flexinodeName)
$flexinodeName=preg_replace("/[^\w\d]/","",ucwords($dbobj->name));
$viewobject[preg_replace("/[^\w\d]/","",ucwords($dbobj->label))]=$dbobj;
}
// view filenames are view-AboutOurTeam.tpl etc in current theme path
$viewfilename="flexinode-$flexinodeName.tpl";
$filename="/usr/share/drupal/".path_to_theme()."/".$viewfilename;
// got a template for this view? make it Smarty
if (file_exists($filename) ) {
$content="<!--- _views_view: $viewfilename --->\n";
$smarty=new SmartyTemplate;
$smarty->assign('flexinode',$viewobject);
$content.=$smarty->fetch($filename);
} else {
$content="<!--- not found _views_view: $viewfilename --->\n";
$content.=$node->body; // default return drupals interpretation
}
}
// print_r($viewobject);
return $content;
}
?>
then my Smarty template for the full flexinode look like flexinode-HumanOrPerson.tpl
<h2>Full node view of a flexinode</h2>
<B>{$flexinode.Description->label}</B> {$flexinode.Description->textual_data}<BR>
{if $flexinode.ContactThisPersonAt->textual_data}
<B>{$flexinode.ContactThisPersonAt->label}</B> {$flexinode.ContactThisPersonAt->textual_data} <BR>
{/if}
and the View template is called view-AboutOurTeam.tpl
<P>
<TABLE border=0>
{strip}
{foreach name=outer item=node from=$viewobject}
<tr bgcolor="{cycle values="#dddddd,#eeeeee"}">
<TD><B>{$node.flexinode.Description->label}</B><BR>
<A HREF="?q=node/{$node.flexinode.Description->nid}">{$node.flexinode.Description->textual_data}</a><BR>
{if $node.flexinode.ContactThisPersonAt->textual_data}
<B>{$node.flexinode.ContactThisPersonAt->label}</B><BR>
{$node.flexinode.ContactThisPersonAt->textual_data}
{/if}
<P>
</TD>
</tr>
</tr>
{/foreach}
{/strip}
</TABLE>
Comments
I need to extend the
I need to extend the views_table part of the views module to define a new view called "smarty template" i think, any comments?
Internet trend watcher, live graphs, add your own stuff free
i dont know what happened,
i dont know what happened, this was working yesterday. but now it seems to be being passed an assoc array instead of an object?? and the hook name is no longer trigggering, try this on for size instead
Internet trend watcher, live graphs, add your own stuff free
Hrm
I question if this really ends up cleaner than the http://drupal.org/node/45475 along with something like vitamin's first tip.
Additionally, the way you're generating $filename is not going to work across implemenations.
Why not hand off with _smarty_callback for the view rendering and just use the node-flexinode-n.tpl for the direct node rendering?