## CategoryRoute Provides a special router for the frontend, that changes (and redirects) a records url to use it's main taxonomy as first path element. Standard Bolt urls: `//` CategoryRoute urls: `///` ### Configuration The extension is configured inside your `designs.cnd.yml` file in `app/config/extensions`. ``` # Enable selected designs modules modules: category-route: true # Configuration for optional CategoryRoute module category-route: # use this taxonomy for first path element taxonomy: categories # enforce route for these contenttypes contenttypes: [articles,galleries,videos] # Set route name for category url for all zones used. Most sites only use the default zone 'frontend' route: frontend: contentlinkcategory ``` You also need to specify a new route for the new urls ***and*** set the old and the new contentlink routes to use the modified controller of this module. Replace the old contentlink route inside your `routing.yml` with this block and change as needed. It has to be placed at same position as the order of routes defines their priority inside bolt/symfony. ``` # legacy route without category - Will redirect to 'contentlinkcategory' if applicable contentlink: path: /{contenttypeslug}/{slug} defaults: _controller: cnd-design.categoryroute.controller.category:record requirements: contenttypeslug: controller.requirement:anyContentType # Route without category contentlinkcategory: path: /{taxonomy}/{contenttypeslug}/{slug} defaults: _controller: cnd-design.categoryroute.controller.category:recordCategory requirements: contenttypeslug: controller.requirement:anyContentType ``` ### Links Since Bolt's change to the new Repository system, overriding the content class is no longer possible as it collides with having new Content and old Legacy Content classes at the same time. We have to use a `link` filter now. This link generator will determine the link to generate from the configured route of the zone `frontend` as specified in your extension configuration under key `category-route.route`. You can enable autozone to get a link for your currently used zone. Template: ``` Relative url for frontend zone: {{ record.title }} Absolute Url for current zone: {{ record.title }} ``` PHP: ``` $link = $app['cnd-design.categoryroute.service']->link($record); ``` **Important** You have to change all templates from `record.link` to `record|link`. ### Canonical The controller does not set the canonical on it's own as it can only react after the template has allready been rendered. You have to set it yourself inside your templates, preferrably using the **cnd/basics** extension. ``` {% set res = canonical.set(record|link) %} ``` ### Teaser Generator The teaser generator for bolt records uses the link method of records by default. This can be changed to this module's new link method by configuring a custom map for the teaser generator in your `basics.cnd.yml` file. Copy the below snippet into your configuration. This snippet changes the generators link to look for a target field first and then call the CategoryRoute's service method `link` if no target was given. ``` teaser: bolt: map: link: - key: target - type: pimple config: key: cnd-design.categoryroute.service method: link ```