Page subset info

Hi all -

I’m trying to work out if kirby is a good fit for a potential new website.
Is there a way to add ‘subsets’ of data with a page in the panel view without it being a subpage.

So for example, let’s say I’m in a page called ‘Developments’ - I want to be able to add ‘house types’ within the panel dynamically, with each attraction having it’s own associated input fields such as name, description. I don’t need these to be their own pages as they won’t exist on their own, and it needs to be done all within the panel by users, so an option to add items from the panel rather than in the code is needed.

So let’s image they hit a plus icon under the title ‘house types’, it brings up a subset of a ‘name’ text field, a ‘description’ text field and an image drop down file. They can enter the info and it will all be associated with that house type. Then they can add a second house type. I need each house type entry to be uniquely identifiable as I’ll reference it later.

Or am I best off just using subpages and never linking to them?

Quite tricky so hard to explain - please let me know if I’m not clear.

Thanks

Isn’t this a typical use case for a structure field? As long as each entry has some information that is unique, like the name or type, you can fetch each entry via this information.

fields:
  housetypes:
    label: House types
    type: structure
    style: table
    fields:
      housetype:
        label: Housetype
        type: text
      name:
        label: Name
        type: text
      description:
        label: Description
        type: textarea
      pic:
        label: Image
        type: image

The alternative are indeed subpages (if you want, in the form of modules).

Thanks for the reply. Let’s say I have a house type called ‘deluxe’ and I want to retreive the picture for the deluxe house type only in my template. How will that image be labelled as belonging to that house type? If I’m not mistaken the content this will create will end up with an image called ‘image’ for every entry I create. I’m not sure what the first ‘housetype’ field is doing there though so maybe I’m missing something.

Thanks

Well, and I’m not quite sure if any of that data, either the house type or the names are unique, but let’s see what you would get in your content file from the example:

Housetypes: 

- 
  housetype: Deluxe
  name: Maison Blueberry
  description: This is a really nice house.
  pic: blueberry.png
- 
  housetype: Standard
  name: Spider Cottage
  description: >
    Somewhere out in the country, beware of
    spiders.
  pic: spider.png

In your template, you can the either loop through the whole collection, or get a specific element:

<?php
// store collection of house types in $housetypes
$housetypes = $page->housetypes()->structure();

// get the one you need, e.g. by name
$blueberry = $housetypes->findBy('name', 'Maison Blueberry');
// get the image for that entry
$blueberryImage = $blueberry->pic()->toFile();
if($blueberryImage) {
echo $blueberryImage;
}
?>

No, the image fields lets you select an image from the page (or drag 'n drop one in), it stores the filename of that image.

Ok yup that’s making sense - just using the findby ‘filter’ for every request.

So would using the pagebuilder plugin be the only way of adding a new housetype field live within the panel?

I’m afraid I don’t quite understand your question. Why would you need the pagebuilder field? That one is useful if your entries need different types of fields but from your description above I don’t see why?

This is how the current setup looks in the Panel:

Structure field: Unlimited number of fieldsets/entries with the same types of fields
Page builder: Unlimited number of fieldsets/entries with different types of fields

Weird, I don’t have the add button. I’ll look into it this morning again.

Really strange. Have you been able to sort this out? If not, could you please post your blueprint, Kirby version etc.?

Hi I reinstalled and all good! File it under ‘who on Earth knows’!

Picking this up again @texnixe, I managed to sort, and so far so good in terms of my testing to see if it’ll work for said application. Now I can add housetypes for a property development. Now what I’d like to do is list all the plots for a development, and match them to the previously added housetypes:

fields:
housetypes:
label: House types
type: structure
style: table
fields:
housetype:
label: Name
type: text
Size:
label: Size (m2)
type: text
ext_image:
label: external image
type: image
floorplan:
label: floorplan image
type: image
elevation:
label: elevation image
type: image

  plots:
    label: Plot Availability & Pricing
    type: structure
    style: table
    fields:
      plot:
        label: Name
        type: text
      plot_housetype:
        label: Housetype
        type: select
        options:
          Pacific: Pacific
          Blueberry: Blueberry
      availability:
        label: Sold?
        type: toggle
        text: yes/no

So in the above example, let’s say we’ve added the housetypes ‘blueberry and pacific’ - what is the best way to loop through these and add them as options in the select field in the plots structure field?

The plan then is to somehow retreive this info on an interactive SVG map - I’m trying to test one idea at a time, but thought I’d let you and anyone else know the ultimate goal in case there’s a better way of doing it.

There is currently no native way of querying a structure field, but there’s always a solution, in this case in the form of two plugins you could use:

Thanks - the first one looks promising but unfortunately it has to be linked directly to the ‘structurepage’ so it’s a bit too inflexible to use for now as I’ll want to use this on various development pages.

The second one might be a bit too complicated for me! For now I might stick with standard text fields and update once the first plugin has been updated (looks like the dev is on it).

For now I’m using the ‘tooltipster’ jquery plugin to show tooltips on my svg site map. The idea is if I hover over the group in the svg called ‘Plot 1’ then it retrieves the info for plot 1 (image, name, price, if sold). Tooltipster uses the following attribute to assign a tooltip:" data-tooltip-content="#tooltip_content", so the start of typical group in an svg for hovering may look like:

<g id="PLOT-24" class="tooltip" data-tooltip-content="#tooltip_content" transform="translate(1002.000000, 431.000000)">

This then references a global element with that id:

<div class="tooltip_templates">
    <span id="tooltip_content">
      <h4>PLOT 1<h4>
      <p><strong>Price:</strong> 169,999</p>
      <p><strong>House Type:</strong> Pacific</p>
      <p>Sold out</p>
        <img src="thumb.jpg" />
    </span>
</div>

I’m not sure if it’d be possible to loop through the housetypes and retreive the info using this ‘global element’ approach. I was thinking there might be a way of creating a unique identifier using the group id name (in this case plot 24) but i’m not sure. Do you have any ideas how Kirby could achieve this? I realise this is a pretty in depth question so please let me know if its beyond the remit of this support forum!

Yes, definitely, your IDs have to be unique anyway, so you use a unique identifier, which in this case would probably be the plot name. The relation to the house type is then defined via the plot_housetype, which allows you to retrieve the housetype information from the housetype structure fields.

Okay, so at least it’s doable. So what would my ‘tooltip_content’ ideally look like then? And in terms of the unique indentifier of the svg group name, are we retrieving that here or are we creating a variable within the svg?

Where is the limit? You can set the page and field individually for each use of the field?

I’m sorry, but this is now going far beyond free Kirby support, I’m afraid.

No problems, thought that might be the case! :slight_smile: