Pages layout table custom value

Hey,

Is there a way to display the title of the selected page in a table layout?

As shown in my screenshot, it currently outputs "value: '{{ page.uuid }}'", but I need it to show the title of the page instead of the UUID. :slightly_smiling_face:

I already checked the doc - Pages section | Kirby CMS

But

 value: "{{ page.title }}"

gives me just the title of the product.

page.yml

        sections:
          publishedProducts:
            label: Veröffentliche Produkte
            type: pages
            parent: site.find('produkte/produkte')   
            layout: table
            templates: 
              - product
            columns:
              title:
                label: Title
                width: 1/3
              solution:
                label: Lösung
                width: 1/6
              category:
                label: Kategorie
                width: 1/6

product.yml


      productsolution:
        type: fields
        fields:
          solution:
            label: Produkt Lösung
            type: select
            options: query
            query:
              fetch: site.find('loesungen').children.listed
              value: '{{ page.uuid }}'
              text: '{{ page.title }}'

      productcategory:
        type: fields
        fields:
          category:
            label: Produkt Kategorie
            type: select
            options: query
            query:
              fetch: site.find('kategorien').children.listed
              value: '{{ page.uuid }}'
              text: '{{ page.title }}'

I haven’t tested it myself, but an idea could be something like

value: "{{ site.find(page.solution).title }}"

(As page.solution should get you the field value which is an UUID that site.find() should resolve to an actual page object)

Work’s. Thank’s :slight_smile:

Actually, just realized since page.solution is a field you can also use the toPage field method. Might look even cleaner

value: "{{ page.solution.toPage.title }}"

@distantnative

Is there any way to get the title of muliply site’s?

publishedSolutions:
            label: Veröffentliche Lösungen
            type: pages
            parent: site.find('kompetenz/losungen')   
            layout: table
            templates: 
              - solution
            columns:
              title:
                label: Title
                width: 1/3
              relatedproducts:
                label: Produkte
                width: 1/6
                # value: "{{ site.find(page.relatedProducts).title }}"
                value: "{{ page.relatedProducts }}"
                # value: "{{ page.relatedProducts.map(productUUID => site.find(productUUID).title).join(', ') }}"
                # value: "{{ page.relatedProducts.map(productUUID => kirby.page('produkte/produkte').find(productUUID).title).join(', ') }}"

I tried diffrent ways - with

value: "{{ page.relatedProducts }}"

I get than -page://… -page://… back, but I need the title of each selected relatedproduct.

Maybe you have any idea?

To output a text representation of complex fields in a table listing, what I do is:

  1. Create a page model class for that page type.
  2. Write my own method that returns a string.
  3. Call that method in the blueprint (e.g. value: "{{ page.relatedProductsPanelSummary }}").

For instance, it might look like:

<?php

use Kirby\Cms\Page;

class ProductPage extends Page
{
	function relatedProductsPanelSummary()
	{
		$titles = [];
		foreach ($this->relatedProducts()->toPages() as $related) {
			$titles[] = $related->title();
		}
		return implode(', ', $titles);
	}
}

In this case it might be doable directly in the blueprint (if the Pages collection resulting from "{{ page.relatedProducts.toPages }}" has a built-in string representation that matches your needs). But if not, or if your needs get a bit more complex and you need custom logic to produce a string or HTML output, a custom method works well.

Hey thanks for the code

That work’s for me.
Is there any change to add a line break?
I tried \n.

<?php

use Kirby\Cms\Page;

class SolutionPage extends Page
{
    function relatedProductsPanelSummary()
    {
        $titles = [];
        foreach ($this->relatedProducts()->toPages() as $related) {
            $titles[] = $related->title();
        }
        return implode(', ', $titles);
    }
}

Maybe ouput like kirby also did

<ul class="k-tag-field-preview k-tags-field-preview k-tags"><li><button data-theme="light" type="button" class="k-tag"><!----><span class="k-tag-text">Produkt</span><!----></button></li></ul>

Escapes like \n work in PHP but only in double quoted strings, not in single quoted strings.

Note that they would produce a newline in the HTML output, but HTML by default does not treat newlines as line breaks, it collapses whitespace (unless you use some specific CSS with white-space).

If you want line breaks you probably need to output HTML code with <br>s, so you would do something like return implode("<br>", $titles);.

Add in your column options type: tags

Thank’s.