I didn’t know about the Hidden Characters plugin — that’s a great thing! What I have done before is to create placeholders. I’ll share that simple solution here in case it is useful for someone. The benefit of it is that it might be easier for some editors, can be used literally everywhere (page titles etc) and becomes very visible and intentional. The con is … it is very visible, maybe ugly? Plus you have to remember to use kirbytext() / kirbytextinline() in your templates.
// in config.php
'placeholders' => [
'-' => '­',
'_' => ' ',
'/' => '<wbr>',
],
<?php
// plugins/placeholders/index.php
Kirby::plugin("tamburlane/placeholders", [
"hooks" => [
"kirbytext:before" => function ($text) {
return Str::template($text, option("placeholders", []), [
"start" => "{",
"end" => "}",
]);
},
],
"fieldMethods" => [
// Helper to remove all placeholder tags, e.g in the panel listings
"stripPlaceholders" => function ($field) {
$text = $field->value();
$field->value = Str::template(
$text,
[
"-" => "",
"_" => " ",
"/" => "",
],
[
"start" => "{",
"end" => "}",
"fallback" => "",
]
);
return $field;
// Option: run ->kti() then unhtml
//return str::unhtml(kti($field));
},
],
]);
Note the default start/end is double braces but I changed to single braces to make it less noisy.
Finally another tiny plugin to create a nowrap kirbytag just for fun:
<?php
// plugins/kirbytags/index.php
Kirby::plugin('tamburlane/kirbytags', [
'tags' => [
'nowrap' => [
'html' => function($tag) {
return '<span style="white-space: nowrap;">'.$tag->value().'</span>';
}
],
]
]);
In the panel editors use it like this:
Non-breaking space:
”10{_}kg of sugar”
Soft hyphen:
”The inter{-}national”
Word break opportunity :
”super{/}long{/}identifier{/}name”
Nowrap kirbytag keeps a bunch of words together as a lazy alternative to lots of non-breaking spaces:
”Now presenting (nowrap: Captain Beefheart & His Magic Band) etcetera etcetera”
In your templates
you use $text→kt() or $text→kti() to render.