Display data on multiple pages

Hello there. I am very new to Kriby and a bit stuck on how to best start to manage this.

I have a list of services I would want to display on both the homepage and services page.

I have created a services blueprint.
This is visible on the site.yml (/panel/site) overview where I can add new services.

Here are my questions:

  1. How do I display these services also on my actual service page (i mean in the backend) — it would be nice to have an overview on the dashboard but also have the actual services on the service detail page where I have other fields, specific to the services page.

  2. How do I display these services on the actual php layouts? Aka I would need to display the services on both the homepage and services pages frontend.

My apologies if this covered somewhere.

:partying_face: Hello and welcome to the Kirby forum.

Can you tell us how the list oft services is structured?
Are these pages or a structural field?
Do you want to display all services on the homepage, for example, or a specific selection?
For a better understanding of the structure of your blueprint, I would appreciate it if you could post the code here.

In your services.yml blueprint, add a pages section to display the children, see Starterkit notes.yml blueprint for an example.

In the frontend php templates, you can fetch a page by its slug, so while you would use $page->children() in your services.php template, you would use this in home.php

if ($p = page('services') {
  $services = $p->children()->listed();
  //
}

See home.php in the Starterkit, where we do the same, i.e. fetch children of the photography page.

Thanks for the help, but it sounds too complex.

I will try to recap all in formation.

1, I am looking for a data type called “services” — these have two fields: Title and Description
These services do not need any deeper page. However, they will be displayed on the homepage and our services page.
2. On site/panel I would love to have an overview of these services and the ability to add/edit them
3. On the homepage and our services back end page. I would love to be able to add these exact same services, obviously when one is updated, it reflects on the site/panel
4.On the front end, I wish to be able to grab a list of these services on both the homepage and our services page.

I understand that “notes” follow a similar complex, but it feels too complex for what I am after.

I read the github demo’s code of restaurant and the menu looked like a good solution. However. I am unable to ensure that when I update on the site/panel aka site.yml is updated also in the pages/home.yml

I tried my best to read the docs over but I fail on how to make sure that the data is updated on all instances.

Here is my code
/blueprints/fields/services

label: Services
type: structure
columns:
 Title: true
 description: true
fields:
 Title:
   label: Title
   type: text
 description:
   label: Description
   type: text

/site.yml

     Services:
       extends: fields/services
       label: Our Services

pages/home.yml

     Services:
       extends: fields/services
       label: Our Services

Ok, so you have a structure field called services. I originally thought it was a page with child pages.

Out of the box, this cannot be displayed in two places in the Panel. Or put otherwise, you would either have to fill in the data in two places, or make sure via hooks that when one field is changed, the other is updated. Does not sound like such a great idea.

If I were you, I would only add this information in one place, e.g. the site.yml blueprint, which is then stored in site.txt and can be accessed anywhere in the frontend via $site->services()->toStructure();

For the frontend, you can then fetch the field content from the page/site where it is stored whereever you need it.

Thank you for your clarification! that solves a lot of head scratching.
I will use these types of data as you suggested.

Works fine. Too bad they can not be visible on page level in the back-end. but I guess my customer will be happy enough with this.

ps. it came to my attention that when using a title field (text) and description (textarea) that when you tab out of the title field it firstly selects the markup buttons of the textarea instead of the text part.

It seems to be possible to save without adding any data causing an empty entry. Is there an easy way to remove empty entries automatically?
Adding required: true definitely helps, but I am just wondering.

I’d just filter them out in the frontend, but with two fields, wondering which field you would filter by, both maybe.

I think it makes the most sense to require the fields you want filled.