Stuck on a hierarchy problem

No, a parent page where the select field options are defined in a structure field. The items themselves are subpages of this parent page and have a select field where you select the category.

Yeah, there won’t be a lot of items, so I could look into that!

Sure, but i mean drive the url from the tag field on each pagee (not a central one in the site.yml or a parent page)rather then marking the article as belonging to something. That way the router would pick it up without having to manually correct the page.

But that doesn’t make sense because then you end up with more than your three categories when the tags suddenly change.

Yeah, that’s what I meant :smiley: Sorry, by first level I meant parent page.

Just one last question:
If the items are subpages, would I be able to sort them by category on their parent page in a pages field/section? (Like with different headlines.)

Like:

Publications
– item 1
– item 2 etc.

Media
– item 3
– item 4
– item 5

If not, I could use the info: {{page.something}} to display the select field value to make the items more distinguishable.

A field doesn’t make sense (because a field is for selecting pages). In a standard pages section you cannot filter pages by field, though, unless you use the pagesdisplay section instead of a normal pages section. But then you would need an addition section for drafts.

Thats ok i think though, there are 3 for now, but i understood they want the ability to add new ones on the fly as required.

No, it’s not about adding new ones (or not in the first place), but changing the display name of the categories.

And yes, you can show the category in the info. And if you use a page model, you can also show the correct display name.

1 Like

Yeah, I would be ok by having a draft section where all the categories are mixed and three pagesdisplay sections where the pages are filtered by category.

But I have to check if the pagesdisplay accepts dynamic values as filter options or just preset values inside the blueprint.

Why would they have to be dynamic? You only have those three categories and their values are fixed. What probably has to change is the headline (show the display name of the category). But it should be possible to query that from the page model.

1 Like

Oh, yeah, I forgot about that :smiley:

Yeah, maybe I leave the headline out and just put the category into the info {{}}, since I’m not really that swift with the page models.

The “dynamic” category names as headlines would probably not work because the key-value pair structure field are on the same page, so the page would have to be refreshed for the headlines to update.

Anyway, your structure field should probably look like this:

categories:
  type: structure
  default:
    - value: media
    - value: publication
    - value: presentation
  fields:
    value:
      type: text
      disabled: true
    displayName:
      type: text

Note that the default values will only be created on page creation, so you might have to add them manually if the page already exists.

With this setup, the editor can only change the display name, not the value.

Query this field in child blueprint

     category:
        type: select
        options: query
        query:
          fetch: page.parent.categories.toStructure
          value: "{{ structureItem.value }}"
          text: "{{ structureItem.displayname.or(structureItem.value)  }}"

The model to show the displayname:

class PagenamePage extends Page
{
    public function getDisplayName()
    {
        $structure = $this->parent()->categories()->toStructure();
        $item = $structure->findBy('value', $this->category()->value());
        if ($item) {
            if ($item->displayName()->isNotEmpty()) {
                return $item->displayName();
            } else {
                return ucfirst($item->value());
            }
        } else {
            return null;
        }
    }
}

(You have to change Pagename to the name of your child page blueprint)
In template:

<?= $page->getDisplayName() ?>

This will either return the displayname if not empty, or the uppercased value (or nothing if the field is empty).

You can then also use this method in the info text. Query language doesn’t seem to work for headlines, it seems.

1 Like

Oh, thanks! That’s very nice of you!
Cool!

Thanks texnixe for helping so much!

It works fine! I decided not to show any info text or headlines though because of course the headlines or info text doesn’t update on the fly (as in immediately after clicking on the save button after a category name change in the structure field). It needs a page refresh. Maybe I’ll check out the update after hooks.