This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Username123
Username123

How to add Blog "category.slug" to "activeMenuItem"?

function onInit() {$this['activeMenuItem'] = ???;}

Show category.slug in post:

{% for category in post.categories %} {{ category.slug }} {% endfor %}

or

{{ post.categories[0].slug }}

daftspunky
daftspunky

Hey, try this:

function onInit() {
    $this['activeMenuItem'] = $this->post->categories[0]->slug ?? null;
}
Username123
Username123

daftspunk said:

Hey, try this:

function onInit() {
   $this['activeMenuItem'] = $this->post->categories[0]->slug ?? null;
}

Works with function onEnd()

And can be removed ?? null

Thank you very much!!!

daftspunky
daftspunky

Great! ?? null is for exception handling in case the post has no categories.

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.