Better solution for fetching nodes list in templates

Marcus

Well-known member
Currently I fetch the current node and all parent nodes with

<div style="display:none"><xen:include template="breadcrumb"></xen:include></div>

I modify this template to give me the right output for this include, and the regular output if it is called not from my template. This is not perfect. Is there another possibility of getting both the a) actual node list and b) all nodes? Thanks.


The nodes aren't available in the global scope:(

you'll need to add the nodes
PHP:
    public function actionQuickNavigationMenu()
    {
        $route = $this->_input->filterSingle('route', XenForo_Input::STRING);
 
        /* @var $nodeModel XenForo_Model_Node */
        $nodeModel = $this->getModelFromCache('XenForo_Model_Node');
 
        $nodes = $nodeModel->getViewableNodeList(null, true);
        $nodeTypes = $nodeModel->getAllNodeTypes();
 
        $quickNavMenuNodeTypes = XenForo_Application::get('options')->quickNavMenuNodeTypes;
 
        if (!isset($nodeTypes['_all']) && !in_array('_all', $quickNavMenuNodeTypes))
        {
            $nodes = $nodeModel->filterNodeTypesInTree($nodes, $quickNavMenuNodeTypes);
        }
 
        $nodes = $nodeModel->filterOrphanNodes($nodes);
 
        $selected = preg_replace('/[^a-z0-9_-]/i', '', $this->_input->filterSingle('selected', XenForo_Input::STRING));
 
        $options = XenForo_Application::get('options');
 
        $viewParams = array(
            'route' => $route,
            'nodes' => $nodes,
            'nodeTypes' => $nodeTypes,
            'selected' => $selected,
 
            'homeLink' => ($options->homePageUrl ? $options->homePageUrl : false)
        );
 
        return $this->responseView('XenForo_ViewPublic_Misc_QuickNavigationMenu', 'quick_navigation_menu', $viewParams);
    }
 
It sounds like you are extracting node information from the breadcrumbs on the page. That works if you want to access the current path through the node tree. But it won't give you access to nodes outside of that path.

Exactly what node information do you need and where? Context is required before I can be more specific.
 
Currently I just need the node path, so I make use of the breadcrumbs template. I display the template in addition as I need the information right after <body>.

I am also looking forward for a script that displays the siblings of the father element, and maybe more - thus I need all nodes.

Do you know of the most easy way to accomplish this?
 
Then you will need to create an addon to fetch those other nodes. Ragtek posted example code from XenForo_ControllerPublic_Misc. That code fetches the node records and makes them available as a viewParam for use in the content template (quick_navigation_menu in that example).
 
Top Bottom