Skip to content

Commit

Permalink
Add anootation example to README and add default bootstrap template
Browse files Browse the repository at this point in the history
  • Loading branch information
thormeier committed Apr 17, 2019
1 parent 4421eba commit 8265f78
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ If the current route is `acme_demo_catalogue`, the breadcrumbs would for instanc

Home > Our Catalogue

Since the configuration of the breadcrumbs happens on routing config, it's generally agnostic from _how_ the routing
configuration happens. This means that configuring breadcrumbs for instance via annotations is perfectly possible:

/**
* ...
* @Route(
* "/contact",
* name="course",
* options={
* "breadcrumb" = {
* "label" = "Contact",
* "parent_route" = "acme_demo_home"
* }
* })
* ...
*/

The configuration can also be done in XML and PHP.

### Dynamic routes

If you happen to have dynamic routes or dynamic translations that you need in your breadcrumbs, they
Expand Down Expand Up @@ -174,6 +193,14 @@ Call the twig extension as following:

{# ... #}

### Using the bootstrap template

The bundle also provides a default implementation for [Bootstrap](https://getbootstrap.com/docs/4.3/components/breadcrumb/). It can be used as follows:

# config.yml
thormeier_breadcrumb:
template: @ThormeierBreadcrumb/breadcrumbs_bootstrap.html.twig

### Replacing the default template

If you want to use a custom template, add the following to your config.yml
Expand Down Expand Up @@ -204,7 +231,7 @@ Your custom template might look something like this:

**The replacing of `%%` with single `%` happens inside the template. See *"Dynamic routes"* as why this is needed.**

Have a look at `Resources/views/breadcrumbs.html.twig` to see the default implementation
Have a look at `Resources/views/breadcrumbs.html.twig` and `Resources/views/breadcrumbs_bootstrap.html.twig` to see the default implementations.

### Customize implementations

Expand Down
16 changes: 8 additions & 8 deletions Resources/views/breadcrumbs.html.twig
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{% if breadcrumbs|length %}
{%- if breadcrumbs|length %}
<ul class="breadcrumbs">
{% for crumb in breadcrumbs %}
{% set crumbText = crumb.label|replace({"%%": "%"})|trans(crumb.labelParameters) %}
{% if crumb.route == app.request.get('_route') %}
{%- for crumb in breadcrumbs -%}
{%- set crumbText = crumb.label|replace({"%%": "%"})|trans(crumb.labelParameters) -%}
{%- if crumb.route == app.request.get('_route') -%}
<li class="current">
<a title="{{ crumbText }}">{{ crumbText }}</a>
</li>
{% else %}
{%- else -%}
{% set crumbPath = path(crumb.route, crumb.routeParameters) %}
<li>
<a href="{{ crumbPath }}" title="{{ crumbText }}">{{ crumbText }}</a>
</li>
{% endif %}
{% endfor %}
{%- endif -%}
{%- endfor -%}
</ul>
{% endif %}
{% endif -%}
17 changes: 17 additions & 0 deletions Resources/views/breadcrumbs_bootstrap.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{%- if breadcrumbs|length -%}
<ol class="breadcrumb">
{%- for crumb in breadcrumbs -%}
{%- set crumbText = crumb.label|replace('%%', '%')|trans(crumb.labelParameters) -%}
{%- if crumb.route == app.request.get('_route') -%}
<li class="breadcrumb-item active">
{{- crumbText -}}
</li>
{%- else -%}
{%- set crumbPath = path(crumb.route, crumb.routeParameters) -%}
<li class="breadcrumb-item" aria-current="page">
<a href="{{ crumbPath }}" title="{{ crumbText }}">{{ crumbText }}</a>
</li>
{%- endif -%}
{%- endfor -%}
</ol>
{% endif -%}

0 comments on commit 8265f78

Please sign in to comment.