Problem in creating breadcrumb particle in Twig for Gantry5 ( joomla)

Everything to do with Joomla! 3.x templates and templating.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
nkont
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Mar 26, 2021 9:13 am

Problem in creating breadcrumb particle in Twig for Gantry5 ( joomla)

Post by nkont » Fri Mar 26, 2021 9:26 am

I am trying to create a breadcrumb particle for my theme in joomla. The framework I am using is Gantry 5 with a Rocket Theme template. I found a php code to get the idea of how to create the breadcrumbs which is https://www.kittell.net/code/php-create ... readcrumb/. So I created in Custom file in the tempalte directory, my twig file with the following code:

Code: Select all

{% extends '@nucleus/partials/particle.html.twig' %}

{% macro  breadcrumb(seperator="&raquo", home="Home") %}
  {% set path = [parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH|split('/')] %}

{# build our "base URL #}
{% set base = _SERVER['HTTPS'] ? 'https' : 'http' ~ '://' ~ _SERVER['HTTP_HOST'] ~ '/' %}
{% set breadcrumbs = ["<a href="~base~">"~home~"</a>"] %} 

{#Find out the index for the last value in  path array #}
{% set last = path|last %}

{# Build the rest of the breadcrumbs #}
{% for x,crumb in path %} 
{#  "title"  will be displayed (strip out .php and turn '_' into a space #}
{% set title = ucwords(str_replace([('.php', '_'), [('', ' '), crumb]] ) %}
  {% if (x != last) %}
    {#  If we are not on the last index, then display an <a> tag #}
    {% set breadcrumbs = "<a href="~base~crumb~">"~title~"</a>" %}
    {% else %} 
    {# Otherwise, just display the title #}
    {% set breadcrumbs = title %}
  {% endif %}               
{% endfor %}
{% set final = [separator,breadcrumbs]|join %}
{% endmacro %}

{% import _self as result %}
and then I tried to import it in my block:

Code: Select all

{% block particle %}                     
 <div class="breadcrumb_particle{{ particle.css.class }}" role="navigation">    
  {{ result.breadcrumb(final) }}  
</div>
{% endblock %}
Of course I get the message Error while rendering breadcrumb_particle particle. SInce I am only 2 days old in twig and particle development, I dont know if my syntax is wrong or the whole idea, or both XD. Any help would be much appreciated.
Last edited by toivo on Fri Mar 26, 2021 10:26 am, edited 1 time in total.
Reason: mod note: retitled

Mr. Wimpy
Joomla! Explorer
Joomla! Explorer
Posts: 448
Joined: Fri Dec 02, 2005 10:46 am
Location: The Netherlands

Re: Problem in creating breadcrumb particle in Twig for Gantry5 ( joomla)

Post by Mr. Wimpy » Fri Mar 26, 2021 10:41 am

Is there any reason why you want to use this instead of Joomla's own breadcrumb module?

nkont
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Mar 26, 2021 9:13 am

Re: Problem in creating breadcrumb particle in Twig for Gantry5 ( joomla)

Post by nkont » Fri Mar 26, 2021 4:48 pm

@Mr. Wimpy Because my team does not like the fact that breadcrumbs get their styles from joomla itself and not from the theme as the other particles that we used. I don't really know if this makes sense but yeah, it is what it is XD


Locked

Return to “Templates for Joomla! 3.x”