Messa
January 30, 2024, 1:32pm
1
Is there any change to pass HTML to fieldMethods field?
I use that for a table layout - Customer want if true that there is a green circle
Kirby::plugin('messa/booltotext', [
'fieldMethods' => [
'convertBoolToText' => function ($field) {
if( $field->bool() ) {
$field->value = '<div style="height: 10px; width: 10px; background-color: green;"></div>';
} else {
$field->value = '';
}
return $field;
}
]
]);
Messa
February 19, 2024, 7:02pm
2
There is no option here. I don’t want to bother anyone with this, but I haven’t been able to find a suitable solution yet.
texnixe
February 19, 2024, 7:49pm
3
What is your question? Or what does not work?
Messa
February 20, 2024, 1:19pm
4
@texnixe I have there a list of pages and I want to add a symbole if the toggle get me true back.
And i thought I could pass HTML to the field. In the object i have a toggler field called referenz.
objects:
label: Objekte
type: pages
image: page.thumbnail.toFile
template: object
search: true
status: listed
create:
- object
layout: table
columns:
info: false
subheader:
label: Untertitel
width: 1/3
referenz:
width: 1/6
value: "{{ page.referenz.convertBoolToText }}"
on Kirby version 4.0.1 I have this code added to show a label - that works but no HTML
Kirby::plugin('matthiasgmeiner/booltotext', [
'fieldMethods' => [
'convertBoolToText' => function ($field) {
if( $field->bool(true) ) {
$field->value = 'Referenz Objekt';
} else {
$field->value = '';
}
return $field;
}
]
]);
But after a update to Kirby CMS 4.1.0 it don’t pass me “Referenz Objekt” if it’s true.
And I add this to a ticket on github - but also if I go back to 4.0.1 - I can’t find a way to passt HTML
Kirby::plugin('matthiasgmeiner/booltotext', [
'fieldMethods' => [
'convertBoolToText' => function ($field) {
if( $field->bool(true) ) {
$field->value = <span style="height:15px; width: 15px; background: green;"></span>;
} else {
$field->value = '';
}
return $field;
}
]
]);
Screenshot V 4.0.1 (Show “Referenz Objekt” vs. V 4.1.0 show the toggler)
So my basic problem is I want to add HTML insteat of a Text and the second is maybe a kirby 4.1.0 bug.
texnixe
February 20, 2024, 2:48pm
5
You need to set the type to html
, default is text
Messa
February 21, 2024, 7:56am
6
Ah thanks. Type html works.
referenz:
width: 1/6
value: "{{ page.referenz.convertBoolToText }}"
type: html