|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
whitetulip Smarty n00b
Joined: 23 Sep 2007 Posts: 2
|
Posted: Sun Sep 23, 2007 10:46 am Post subject: Make a tree in smarty |
|
|
Hi all,
I need to know anything about making a tree in smarty,
I just wanna know how to view the nodes in a tree form in the template.
Could anyone help? |
|
Back to top |
|
lars.koenig Smarty n00b
Joined: 19 May 2008 Posts: 1
|
Posted: Mon May 19, 2008 7:13 am Post subject: tree in smarty |
|
|
Hello,
I am also looking for a tip to create a tree with nodes in smarty.
Thx for an answer
L. |
|
Back to top |
|
Celeb Administrator
Joined: 17 Apr 2007 Posts: 1025 Location: Vienna
|
|
Back to top |
|
student of life Smarty n00b
Joined: 09 Sep 2008 Posts: 3
|
Posted: Tue Sep 09, 2008 7:21 am Post subject: |
|
|
thanks very helpful. |
|
Back to top |
|
Corith Smarty n00b
Joined: 05 Mar 2009 Posts: 1
|
Posted: Thu Mar 05, 2009 7:36 pm Post subject: |
|
|
I use the one at
pear.php . net / package / HTML_TreeMenu
I created a new class (NodeTree) to allow me to pass mysql data and built the tree dynamically, then dump it to variable.
The following code may seem incomplete. It was designed for a specific need, a list of either checkboxes or radio buttons for hierarchal data, but it might help spur others along.
Code: |
$smarty->assign('primaryNodes', DisplayTree() );
function DisplayTree($nodeData)
{
//$nodeData = "SELECT Node_ID, NodeLabel, ParentID FROM T1"
$nodetree = new NodeTree();
$nodetree->ChildControl = 'radio'; //or 'checkbox'
$nodetree->ChildControlName = 'Nodes[]';
$nodetree->DataSource = $nodeData;
//$Checkeddata = "SELECT Node_ID FROM T2 where pk=$thisrecord";
$nodetree->CheckedData = $CheckedData;
return $nodetree->DataBind(false);
}
class NodeTree
{
public $DataSource;
public $ChildControl;
public $ChildControlName;
public $CheckedData;
public $ShowLinks = false;
public function DataBind($echo = true)
{
require_once('TreeMenu.inc');
$data = $this->DataSource;
//create an associative array of nodes, key is NodeID, value is HTML_TreeNode object
$nodelist = Array();
for($i=0; $i<sizeof($data); $i++)
{
if ($this->ShowLinks)
$data[$i]['NodeLabel'] = '<a href="node.php?nodeid='.$data[$i]['Node_ID'].'">'.$data[$i]['NodeLabel'].'</a>\n';
if ($data[$i]['Node_ID']==$_GET['nodeid'])
{
$ChildControl = '';
}
else {
switch ($this->ChildControl)
{
case 'checkbox':
$checked = ($this->FindCheck($data[$i]['Node_ID'])) ? ' checked ' : '';
$ChildControl = '<input type="checkbox" name="'.$this->ChildControlName.'" value="'.$data[$i]['Node_ID'].'" '.$checked.'> ';
break;
case 'radio':
$checked = ($this->FindCheck($data[$i]['Node_ID'])) ? ' checked ' : '';
$ChildControl = '<input type="radio" name="'.$this->ChildControlName.'" value="'.$data[$i]['Node_ID'].'" '.$checked.'> ';
break;
}
}
$nodelist[$data[$i]['Node_ID']] =
new HTML_TreeNode (
array('text' => $ChildControl.$data[$i]['NodeLabel'], 'link' => '', 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => false)
)
;
}
$icon = '';
$pageicon = '';
$expandedIcon = '';
$menu = new HTML_TreeMenu();
for($i=0; $i<sizeof($data); $i++)
{
//add top level nodes to top
if ($data[$i]['ParentID'] == 0 )
{
$menu->addItem($nodelist[$data[$i]['Node_ID']]);
}
else //or to a matching parent
{
if ($nodelist[$data[$i]['ParentID']])
$nodelist[$data[$i]['ParentID']]->addItem($nodelist[$data[$i]['Node_ID']]);
}
}
// // Create the presentation class
$treeMenu = &new HTML_TreeMenu_DHTML($menu, array('images' => 'images', 'defaultClass' => 'treeMenuDefault'));
//and render
if ($echo)
{
$options['echo'] = $echo;
echo '<script src="scripts/TreeMenu.js" language="JavaScript" type="text/javascript"></script>';
$treeMenu->printMenu($options);
}
else
{
return '<script src="scripts/TreeMenu.js" language="JavaScript" type="text/javascript"></script>'.$treeMenu->printMenu($options);
}
}
private function FindCheck($match)
{ $returnvalue = false;
$data = $this->CheckedData;
for($i=0; $i<sizeof($data); $i++)
{
if ($data[$i][0] == $match)
$returnvalue = true;
}
return $returnvalue;
}
}
|
|
|
Back to top |
|
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Wed Mar 18, 2009 8:43 pm Post subject: Another option |
|
|
Sometimes, you can use this option too:
The websites like dynamic drive (http://www.dynamicdrive.com/) provide enough resources, menus using javascript and css.
Using some simple tweaks in the stored data (array or database), you should be able to feed the javascript the exact way.
By this, nothing becomes harder, but highly customizable too (as you can find the documentation in such sites too). |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|