1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Breadcrumb in Admin Template

Discussion in 'XenForo Development Discussions' started by Helmut2509, Oct 31, 2013.

  1. Helmut2509

    Helmut2509 Member

    hello,
    I am rather new to Xenforo and I am just developing an admin add-on.
    I would like to have a breadcrumb menu on top of the admin template and don't know how to manage this.
    As far as I can see, my template has to be embedded in the PAGE_CONTAINER, because the latter includes the content_header subtemplate, which displays the breadcrumb menu.
    Any idea how to manage this?
    thanks for your help, Helmut
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    This is how I added breadcrumbs to my templates:
    Code:
    <xen:navigation>
        <xen:breadcrumb href="{xen:link page}">{xen:phrase page}</xen:breadcrumb>
    </xen:navigation>
     
  3. Helmut2509

    Helmut2509 Member

    is this the only way? when I look at the *official* admin templates, there is no breadcrumb tag..
     
  4. Jeremy

    Jeremy XenForo Moderator Staff Member

    You can provide a source array to build them from in your controller:
    Code:
    <xen:navigation>
        <xen:breadcrumb source="$nodeBreadCrumbs" />
    </xen:navigation>
    I don't have access to the admin templates at the moment, but that should work.
     
  5. Lawrence

    Lawrence Well-Known Member

    To get the breadcrumbs to show automatically in the AdminCP for your add-on you do not need the <xen:navigation> tag, this is handled by the route/prefixadmin/name_of_your_addon.php file. The reason yours is not showing is you do not have the admin navigation id for your add-on set in the route admin prefix handler (or there is a typo there).

    PHP:
    class IcewindDaleRP_IcewindDale_Route_PrefixAdmin_ShopItems implements XenForo_Route_Interface
    {
        public function 
    match($routePathZend_Controller_Request_Http $requestXenForo_Router $router)
        {
            
    $action $router->resolveActionWithIntegerParam($routePath$request'item_id');
            return 
    $router->getRouteMatch('IcewindDaleRP_IcewindDale_ControllerAdmin_ShopItems'$action'iwdShopItems');
        }

        public function 
    buildLink($originalPrefix$outputPrefix$action$extension$data, array &$extraParams)
        {
            return 
    XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix$action$extension$data'item_id''name');
        }
    }
    The admin navigation id for my shop add-on above is: 'iwdShopItems' . If i change that id, the breadcrumbs disappear. Here is the top portion of my admin template for listing shop items, as you can see, no <xen:navigation> tag is used:

    HTML:
    <xen:title>{xen:phrase iwd_shop_items}</xen:title>
    
    <xen:topctrl>
    <xen:if is="{$images}">
        <a href="{xen:adminlink iwd-shop-items/add}" class="button">+ {xen:phrase iwd_create_new_item}</a>
    </xen:if>
        <a href="{xen:adminlink iwd-shop-items/upload}" class="button">+ {xen:phrase iwd_upload_image}</a>
    </xen:topctrl>
    
    <xen:require css="filter_list.css" />
    <xen:require js="js/xenforo/filter_list.js" />
    
    <xen:form action="{xen:adminlink iwd-shop-items/toggle}" class="section AutoValidator">
    And here is the SS showing the breadcrumb:
    admin_image.png

    When I select an item to edit, I do then use the <xen:navigation> tag in my shops add/edit template to show the editing item in the breadcrumb:
    HTML:
    <xen:require css="iwd_shop.css" />
    <xen:title>{xen:if '{$item.item_id}', '{xen:phrase iwd_edit_item}: {$item.item_name}', '{xen:phrase iwd_create_new} {$item.item_type}'}</xen:title>
    
    <xen:if is="{$item.item_id}">
        <xen:navigation>
            <xen:breadcrumb href="{xen:adminlink iwd-shop-items}#{xen:helper listitemid, $item.item_id}">{$item.item_name}</xen:breadcrumb>
        </xen:navigation>
    </xen:if>
    and that results in:
    Image_1.png
     
    tenants likes this.
  6. Helmut2509

    Helmut2509 Member

    The variable $nodeBreadCrumbs is empty, so this does not work.
     
  7. Jeremy

    Jeremy XenForo Moderator Staff Member

    You need to define it yourself in controllers.
     
  8. Helmut2509

    Helmut2509 Member

    Could you give me a clue of how to define the value of the $nodeBreadCrumbs variable?
     
  9. Navo

    Navo Member

    I use this in my controller.
    Code:
            $breadCrumbs['roster'] = array(
                'value' => 'Roster',
                'href' => XenForo_Link::buildAdminLink('full:roster')
            );
    You can copy paste this code more time that will add more links in your breadcrumbs like this:
    Code:
            $breadCrumbs['roster'] = array(
                'value' => 'Roster',
                'href' => XenForo_Link::buildAdminLink('full:roster')
            );
            $breadCrumbs['nieuwteam'] = array(
                'value' => 'Nieuw team',
                'href' => XenForo_Link::buildAdminLink('full:roster/nieuwteam')
            );

    After you do that just send it to the template with:
    Code:
            $viewParams = array(
                'breadCrumbs' => $breadCrumbs,
            );
    And use in your template:
    Code:
    <xen:navigation>
        <xen:breadcrumb source="$breadCrumbs" />
    </xen:navigation>
    I think there are better ways but it is working.
     

Share This Page