On Octobercms blog component currentCategorySlug cannot pass through macro

28 Views Asked by At

I'm using blog category list component to display categories with subcategories. This is the code on a partial:

{% import _self as list %}
{% macro render_cats(categories) %}
{% import _self as list %}
{% for category in categories %}
{% set postCount = category.post_count %}
<li class="{{ category.slug == currentCategorySlug ? 'active' }}">
    <a class="" href="{{ category.url }}">{{ category.name }}</a>
    {% if postCount %}
    <span class="">
        {{ postCount }}
    </span>
    {% endif %}
</li>
{% if category.children|length > 0 %}
<ul>
    {% set categories=category.children %}
    {% set currentCategorySlug=currentCategorySlug %}
    {{ list.render_cats(categories) }}
</ul>
{% endif %}
{% endfor %}
{% endmacro %}

<div class="">
    <h3 class="">Categories</h3>
    {% if blogCategories.categories|length > 0 %}
    <ul class="">
        {% set categories = blogCategories.categories %}
        {% set currentCategorySlug = blogCategories.currentCategorySlug %}
        {{ list.render_cats(categories) }}
    </ul>
    {% else %}
    <p>No categories were found.</p>
    {% endif %}
</div>

Everything is working fine except currentCategorySlug implementation. It seems that currentCategorySlug cannot pass through macro. Any thoughts please.

0

There are 0 best solutions below