Have section with list of child pages. For better overview want to print some additional info next to each child page title.
Can not figure out how to conditionally put icon to be show for each page in panel list. Will appreciate any advice. Part of blueprint:
- width: 1
sections:
users:
label: "People"
text: "{{ page.content.title }} | | {{ page.content.married ? <want to put check icon here> : '' }}"
type: pages
layout: list
templates:
- people
You can use the fields directly as page.title, page.married - no need to go through the content object unless your field names conflict with page method names, but those don’t
Use the field method toBool to ensure that your page content properly works with the ? : statement
You have to use {< >} instead of {{ }} if you want to put out HTML
If you want to load the SVG, I would actually suggest to create a page method where you put all the logic and then you just to {< page.yourPageMethod >}
Yes, sadly not directly with <k-icon> but you can use the actual SVG string directly: <svg aria-hidden="true" class="k-icon" ><use xlink:href="#icon-check" /></svg>
Still better to use toBool cause page.married/page.content.married will give you a field object, which will always be true.
I’d argue that it can make sense to always go via the content object to prevent such clashing issues with Kirby methods. I’ve seen more than one person doing this to have consistent coding style.
Fair enough, when you aren’t as familiar with what is a protected Mable or not, always going viable content object will make sure that you not unknowingly run into a conflict at some point.
Was able to show Kirby icon as @distantnative suggested, but when trying it conditionally - it does not show up. Checked content folder - value is true for married. Is syntax for inserting condition correct?
You need to wrap it as a string: "<svg .... >". But you will run into nesting problems with the other ", inner ' - too many levels. That’s why it’d be better to move that code into a page method:
public function marriedIcon()
{
if ($page->married()->toBool()) {
return '<svg style="display: inline-block" aria-hidden="true" class="k-icon"><use xlink:href="#icon-check" /></svg>';
}
}
The suggested code would have gone into a page model. As a page model method, the method is specific to this page type, whereas the page method you are using now can be used with any page type.
Right, page.content.uuid gets the value stored in the content file, whereas page.uuid is a native Kirby method that returns the “full” uuid including the model: $page->uuid() | Kirby CMS