I have a foreach which displays titles and some other information from all the child pages of a certain parent. Each page has some tags (named “category”) assigned (wjth a “tags” type field).
I am trying to list all the tags assigned to a page as a data attribute values to the div which contains each child page.
The result should be like this:
<div class="article" data-tags="photography interaction-design architecture web-design">
I am using this inside the data-tag attribute to achieve this result:
<?php foreach ($item->category()->slug()->split(",") as $category): ?><?= $category ?><?php endforeach ?>
This is the result I get:
I see two problems here:
- The tags are not separated by spaces when they are displayed as slugs (everything is merged as a unique tag).
- There is no distinction between single-word tags and multiple-word tags.
I tried other ways but (with no luck) but this seemed the more correct one to me.
Do you have any suggestions?