kirby
kirby copied to clipboard
Harmonize table layout options for sections and structure field
description
hey there 🌳 🍃
both pages sections with layout: table
and structure fields kind of share the same table view. also their columns can both be customised. see here and here. however, the options to modify columns are very different. pages sections for example can show modified labels
or values
, including the ability to use kirby’s query language. or even show html. structure fields can’t.
expected behavior
i was actually expecting these areas to share the same logic. and was quite surprised when i found out structure fields are very limited in comparison to pages sections. are you planning to align the column options at some point? or is there a reason why this cannot be done that i am not seeing?
thank youuuu ♥️ ✨
to reproduce
pages section
type: pages
label: something
layout: table
columns:
something:
width: 1/2 #working
label: custom #working
value: '{{ page.something }}' #working
structure field
type: structure
label: something
columns:
something:
width: 1/2 #working
label: custom #not working
value: '{{ page.something }}' #not working
your setup
kirby version
3.7.1
I'd say the difference comes from the fact that the sections and the structure field come from very different directions and only recently began sharing the same table layout. It would certainly make sense to harmonize them for a better consistency.
Regarding the label: You can currently set that with the fields
property of the structure
field, see the second example here: https://getkirby.com/docs/reference/panel/fields/structure#table-columns__example
@jaro-io Could you elaborate a bit on how you would like to use query syntax in the structure field columns? Your example of '{{ page.something }}'
doesn't make much sense to me as the structure field table is of course intended to display the value(s) of the structure field and not just any data.
@distantnative sure, that’s true. i think i have seen structureItem
somewhere before.. can’t remember if this was part of a plugin or of some area within kirby itself. so imagine within your structure you have a field called costs
, it could then be accessed via value: '{{ structureItem.costs }}'
.
does this make sense to you? 🙏🏻 ✨
That is from dynamic options (e.g. select field). But the columns in a structure field are exactly for the fields from the structure field. So you don't need any query here. Just
myStructureField:
type: structure
columns:
costs: # the column name here needs to match the field name below and then automatically use the value
label: My costs # will work after the PR I just opened to fix this bug
fields:
costs:
type: number
of course, of course!
i am just using tons of custom field methods. so instead i would for example want to do something like
myStructureField:
type: structure
columns:
costs:
value: '{{ structureItem.costs.formatPrice() }}'
fields:
costs:
type: number
or something like
myStructureField:
columns:
costs:
type: html
value: '<a href="{{ page.panel.url }}">{{ structureItem.title }}</a>'
fields:
costs:
type: number
would be really great if this would work in the future, like it does for pages sections with table layout.
🌻
I would ask you to post that part as a feature request over at https://kirby.nolt.io
While with the direct field values the Panel can render the table directly in the Panel, your suggestion would require that the Panel first sends the values to the backend where your queries would be rendered by PHP and send back to the Panel. So that's not a small change.
✅