Get text value of tags generated by structure field

Hi,

I am in the weeds a bit with this one, so if my whole approach is off please say! I am setting up a tags field, using values from a structure field elsewhere on the site. This is my structure:

artworkCategories:
 type: structure
 label: Artwork categories
 help: These are the categories available for artworks to be placed in to. There is also the option to display some information about the category, to be displayed when the category filter is applied on the main Art & Artists page.
 sortBy: category asc
 columns:
  category:
   width: 1/3
  categoryInfo:
   width: 2/3
  fields:
   category:
    type: text
    label: Category
   categoryInfo:
    type: writer
    label: Category information
     help: Optional - add some information about the category, to be displayed when the filter is applied
    nodes: false
    marks:
     - bold
     - italic
     - link
     - email
     - clear
    toolbar:
     inline: false
     marks:
      - bold
      - italic
      - '|'
      - link
      - email
      - '|'
      - clear

And this is how I have set up the tags field in the blueprint:

categories:
    type: tags
    label: Artwork categories
    help: Select one or more categories for this artwork. 
    options:
      type: query
      query: site.find("art-artists").artworkCategories.toStructure
      text: "{{ item.category }}"
      value: "{{ item.category.slug }}"

Which is working great. Now I need to output the text value onto the page, rather than the stored value e.g. Contemporary artists rather than contemporary-artists.

I have tried the blueprint method, but that isn’t working, I assume because I am pulling the tag values from elsewhere. What would be my best approach for this?

$variable = 'value that is stored in your page';
$item = $site.find('art-artists')->artworkCategories()->toStructure()->findBy('category', $variable);

echo $item->categoryInfo();

Of course, with the necessary checks for an existing page and item added…

Hi,

Thanks for the quick reply. I can’t see how that works, sorry. This is what I have in the content file for the structure:

Artworkcategories:

- 
  category: 'British & European'
  categoryinfo: ""
- 
  category: Contemporary artists
  categoryinfo: ""
- 
  category: New additions
  categoryinfo: ""
- 
  category: Sculpture
  categoryinfo: ""

And this is what ends up saved in the content file for the page on which I want to display the tags:

Categories: contemporary-artists, sculpture

I want them saved as slugs as I am eventually going to use them as filters in the url. But right now I need to just output on the page the original category text for the selected tags e.g. British & European rather than british-european.

What exactly don’t you understand? Please post the code to render your tags as it is atm.

Sure, this is what I have:

<ul>
  <?php foreach ($page->categories()->split() as $category): ?>
  <li>
    <?= $category // just to test - this outputs e.g. contemporary-artists ?>

    <?php
      $categoryfromStructure = $site->find('art-artists')->artworkCategories()->toStructure()->findBy('category', $category);
      echo $categoryfromStructure->category(); // this outputs nothing, I think because my slugified category stored on the page doesn't match the one stored in the structure
    ?>
  </li>
  <?php endforeach ?>
</ul>

Right, the sluggified value is the problem (missed that part), but there is a solution. Need to use filter() though, then fetch the first item:

$categoryfromStructure = $site->find('art-artists')->artworkCategories()->toStructure()->filter(fn($item) => $item->category()->slug() === $category)->first();