Howto get current navigation ID or nav key

edited February 2017 in Modules
Hello,

I have a view file.
In code I want to retrieve the ID of the current navigation item,
Because I want to echo all child navigation items from this branch in my site:


---------------------
What I HAVE
---------------------

I have a navigation item with ID 37.
But I don't want to hardcode the id (see below) because this view will be used at different points in my navigation.


$nav = fuel_nav(array(
'parent' => 37,
'render_type' =>'array'
)
);

-----------------------
What I NEED
-----------------------

I need something like this:

$currentNavID = $this->fuel->pagevars->retrieve('my_nav_id'); // pseudocode; does not work

$nav = fuel_nav(array(
'parent' => $currentNavID,
'render_type' =>'array'
)
);

------------


Best, Gordian

------------

I am new to fuel CMS - but I love it - therefor sorry for this question.
I did not find a solution in the docs and this forum.

------------

Comments

  • edited 10:50AM
    I found a solution but I am not totally satisfied.
    The parameter "parent" of the fuel_nav() function does also understand the "nav key" ( the human friendly version ) of the nav id.

    The documentation says:
    "parent - the parent id you would like to start rendering from. This is either the database ID or the nav array key of the menu item"
    Found here: http://docs.getfuelcms.com/helpers/fuel_helper

    =======================================
    So I can write:

    $nav = fuel_nav(array(
    'parent' => uri_segment(1) . "/" . uri_segment(2),
    'render_type' =>'array'
    )
    );

    =======================================
    It would be nicer to get the whole nav-key with one function call, so I don't need to concat segments. But unfortunately I did not found the right helper function yet.

    Does anyone know a command?!

    ------------


    Best, Gordian

    ------------
  • edited 10:50AM
    That's how we normally do it as well using the uri_segment function and concatenating if necessary.
Sign In or Register to comment.