parent controller detection in block

edited October 2013 in Share
In a v1 install, I have a breadcrumb block that will need to deliver the CMS trail if the main layout / CMS controller is the parent, but a module product trail if called from MY_ controller.

What's the best way to achieve this? At the moment I have set a property in MY_Controller, and any view using that controller will detect it and use the product trail, rendered from a custom library - otherwise it uses the CMS fuel_nav() method. But I'm thinking there is probably a "Fuel Way" I've not considered. Is there a simple Fuel property or method to use to determine if the parent view, layout or controller is CMS driven?

Comments

  • edited 4:09AM
    There are a few parameters you can pass fuel_nav that may help:
    • items - This will tell fuel_nav to use the items you pass it instead of any located in the CMS or views/_variables/nav.php file. So you can pass your custom values to fuel_nav instead of completely rendering it using your custom library (more on Navigation structures here: http://docs.getfuelcms.com/general/navigation)
    • var - You could setup a different navigation structure under a different variable in the views/_variables/nav.php file. The var variable allows you to point to that navigation structure instead of the $nav (e.g. $productnav). For example, you could setup the following in the views/_variables/nav.php:$product = fuel_nav('products', array('find' => 'one', 'where' => array('category_id' => uri_segment(2), 'product); $productnav['products'] = 'Products'; $productnav['products/'.$product->category_name] = array('label' => $product->category_name, 'parent_id' => 'products'); $productnav['products/'.$product->category_name.'/'.$product->slug] = array('label' => 'Product Name', 'parent_id' => 'products/'. $product->category_name);
    • append - This will append items to the fuel_nav array and can be useful in situations where you need to add dynamic information such as your product trail. So for example, perhaps you have a navigation setup for "products", (either in the CMS or in the static views/_variables/nav.php file), and you want to add the navigation items "products/my_category" and "products/my_category/my_product". To do that you would need to add the following :
      $append['products/my_category'] = array('label' => 'My Category', 'parent_id' => 'products'); $append['products/my_category/my_product'] = array('label' => 'My Product', 'parent_id' => 'products/my_cateogry');
      NOTE: parent_id values will need to use the database "id" value if using the CMS
  • edited October 2013
    OK thanks - maybe the append is what I need, I was using the menu class directly.

    My issue was
    1) There was a gap in the urls - eg a list page might be:
    /products/category/automotive/auto-accessories
    & a product item like
    products/category/automotive/auto-accessories/item/1587

    so there was a parent->child void. Once I'd fabricated that and...

    2) I forgot, omitted to use the "active" argument in the menu class eg:
    $this->menu->render_breadcrumb($nav, $current_url)

    it all works OK!!
  • edited 4:09AM
    That makes sense. Any break in the URL's parent/child hierarchy will cause the recursive function calling to stop.
  • edited 4:09AM
    I just tried the "append" for fuel_nav(). Very useful! I wasn't sure how to implement your example (or I got it wrong) so I tried:
    echo fuel_nav( array( 'file' => $this->uri->segment(1), 'var' => 'nav', 'active' => uri_path(), 'append' => array(array( 'label' => 'Some label', 'location' => 'go/there' )) ) );

    which combines a _variables file named the same as the root url segment with the appended value - a nested array.

    In another menu, I needed to have hard-coded vars as well as CMS navigation. I just used 2 fuel_nav(), but would there be a way of using append to make just one list?

    I tried using append and making its array a return_normalized fuel_nav(). But that didn't seem to work.
  • edited 4:09AM
    The correct format would be something like what was mentioned above with the array keys being unique to the set of menu items:
    $append['products/my_category'] = array('label' => 'My Category', 'parent_id' => 'products'); $append['products/my_category/my_product'] = array('label' => 'My Product', 'parent_id' => 'products/my_cateogry');
    If pulling from the database, those unique values are the database ID value. So the parent_id needs to reflect that value if necessary.

    Regarding your questions about using append instead of 2 fuel_nav function calls, I would think that would be append would be a good alternative.
Sign In or Register to comment.