Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Custom routes issue with breadcrumbs url path

I have changed the "categories" to "forum" from Dasboard/Settings/Routes. I can visit the page example.com/forum/xx but the breadcrumbs url path remain the same as example.com/categories/xx. Is it a bug or something I need to change? Thanks.

Route Expression: forum/(.*)
Target: categories/$1
Type: Internal

Answers

  • Can anyone help?

  • hgtonighthgtonight ∞ · New Moderator

    Hello! I must have missed this post the first time around, sorry.

    The URL is used by the dispatcher to determine what code needs to be executed. Routes are (generally) used to change the user facing URL into something more convenient or readable. This dispatcher checks for route matches, converts it internally, then goes about its business using the "original" route. In this case, the dispatcher finds /forum/My-Category and translates that into /categories/My-Category and loads up the categories controller and passes in 'My-Category' as the first argument to the Index() method.

    Setting up a route essentially adds a URL (or a bunch) that still point to the original URL. Route definitions don't change how links are generated. You would have to modify each view, module, or controller that generate links and change them to suit your needs.

    So... not impossible, but it will take a lot of work.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • R_JR_J Ex-Fanboy Munich Admin

    If it is "just" a breadcrumbs display question, then you could take a look at /library/core/class.theme.php:

       public static function Breadcrumbs($Data, $Format = '<a href="{Url,html}">{Name,html}</a>', $HomeLink = TRUE) {
          $Result = '';
    
          if ($HomeLink) {
             if (!is_string($HomeLink))
                $HomeLink = T('Home');
                $Result .= '<span class="CrumbLabel"><a href="'.Url('/').'">'.$HomeLink.'</a></span> ';
          }
    
          foreach ($Data as $Row) {
             $Row['Url'] = Url($Row['Url']);
             $Label = '<span class="CrumbLabel">'.FormatString($Format, $Row).'</span> ';
             $Result = ConcatSep('<span class="Crumb">'.T('Breadcrumbs Crumb', '&raquo;').'</span> ', $Result, $Label);
          }
    
          $Result ='<span class="Breadcrumbs">'.$Result.'</span>';
          return $Result;
       }
    

    Maybe changing the file like that:

    public static function Breadcrumbs($Data, $Format = '<a href="{Url,html}">{Name,html}</a>', $HomeLink = TRUE) {   
       $this->EventArguments['Data'] = &$Data;
       $this->EventArguments['Format'] = &$Format;
       $this->EventArguments['HomeLink'] = &$HomeLink;
       $this->FireEvent('BeforeBreadCrumb');
    

    and afterwards use that event to do a search and replace on the $Data would be possible.

    Doing a search and replace in $Data without a hook directly there should at least be possible.

    Changing core files is ugly and should be avoided, because you will lose that changes on every update.

  • Thanks RJ but I cannot make it to work.

  • hgtonighthgtonight ∞ · New Moderator

    @bluesea said:
    Thanks RJ but I cannot make it to work.

    The key is in this line:

    @R_J said:
    and afterwards use that event to do a search and replace on the $Data would be possible.

    He suggests you modify the core to fire an event which you can hook into via a plugin.

    You still have to come up with the logic/plugin.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Sign In or Register to comment.