Gdn_Theme::breadcrumbs PHP Méthode

breadcrumbs() public static méthode

public static breadcrumbs ( $Data, boolean $HomeLink = true, array $Options = [] ) : string
$Data
$HomeLink boolean
$Options array
Résultat string
    public static function breadcrumbs($Data, $HomeLink = true, $Options = array())
    {
        $Format = '<a href="{Url,html}" itemprop="url"><span itemprop="title">{Name,html}</span></a>';
        $Result = '';
        if (!is_array($Data)) {
            $Data = array();
        }
        if ($HomeLink) {
            $HomeUrl = val('HomeUrl', $Options);
            if (!$HomeUrl) {
                $HomeUrl = Url('/', true);
            }
            $Row = array('Name' => $HomeLink, 'Url' => $HomeUrl, 'CssClass' => 'CrumbLabel HomeCrumb');
            if (!is_string($HomeLink)) {
                $Row['Name'] = T('Home');
            }
            array_unshift($Data, $Row);
        }
        if (val('HideLast', $Options)) {
            // Remove the last item off the list.
            array_pop($Data);
        }
        $DefaultRoute = ltrim(val('Destination', Gdn::router()->getRoute('DefaultController'), ''), '/');
        $Count = 0;
        $DataCount = 0;
        $HomeLinkFound = false;
        foreach ($Data as $Row) {
            $DataCount++;
            if ($HomeLinkFound && Gdn::request()->urlCompare($Row['Url'], $DefaultRoute) === 0) {
                continue;
                // don't show default route twice.
            } else {
                $HomeLinkFound = true;
            }
            // Add the breadcrumb wrapper.
            if ($Count > 0) {
                $Result .= '<span itemprop="child" itemscope itemtype="http://data-vocabulary.org/Breadcrumb">';
            }
            $Row['Url'] = $Row['Url'] ? Url($Row['Url']) : '#';
            $CssClass = 'CrumbLabel ' . val('CssClass', $Row);
            if ($DataCount == count($Data)) {
                $CssClass .= ' Last';
            }
            $Label = '<span class="' . $CssClass . '">' . formatString($Format, $Row) . '</span> ';
            $Result = concatSep('<span class="Crumb">' . T('Breadcrumbs Crumb', '›') . '</span> ', $Result, $Label);
            $Count++;
        }
        // Close the stack.
        for ($Count--; $Count > 0; $Count--) {
            $Result .= '</span>';
        }
        $Result = '<span class="Breadcrumbs" itemscope itemtype="http://data-vocabulary.org/Breadcrumb">' . $Result . '</span>';
        return $Result;
    }

Usage Example

/**
 * Render a breadcrumb trail for the user based on the page they are on.
 *
 * @param array $Params
 * @param object $Smarty
 * @return string
 */
function smarty_function_breadcrumbs($Params, &$Smarty)
{
    $Breadcrumbs = $Smarty->Controller->data('Breadcrumbs');
    if (!is_array($Breadcrumbs)) {
        $Breadcrumbs = array();
    }
    $Options = arrayTranslate($Params, array('homeurl' => 'HomeUrl', 'hidelast' => 'HideLast'));
    return Gdn_Theme::breadcrumbs($Breadcrumbs, val('homelink', $Params, true), $Options);
}