Hey everyone,
Use case
I am using Kirby’s excerpt() helper to display a long text — which works like a charm.
Now I want the user to click a “more” link, which then reveals the rest of the text (on the same page), for example via a simple css display:show
.
Question
I wonder if there is Kirby helper which easily pulls the rest of the excerpt from a field?
Of course, I could use native PHP string splitting to do this. But as the excerpt comes already through the nice Kirby helper, pulling the rest via a short Kirby helper, too, would be great.
Any ideas around this?
I’m not aware of such a helper, but you could create your own, based on the excerpt helper and the str::excerpt()
toolkit method that is used by the helper.
@textnixe thanks for the hint 
I noticed that the excerpt()
function behaves a little bit inconsistent in how it shortens the string.
For example if I use $myField->excerpt(5)
and $myfield
contains the string abc def
, the output is abc...
So the function does not seem to split full words (abc d...
) but shows only the last full word. But sometimes, depending on the string and the value I set, the function splits full words 
This behaviour makes it a little bit difficult to implement a method which can consistently calculate the string of myField
after the excerpt. I created this method, which works fine but returns incomplete strings due to the behaviour described above.
<?
field::$methods['excerptRest'] = function($field, $excerpt) {
if (str::length($field) >= str::length($excerpt)){
$field->value = str::substr($field, str::length($excerpt), str::length($field));
return $field;
}
else {
return false;
}
};
?>
In my template I use:
<?= $myField->excerptRest($myField->excerpt(140)) ?>
to shortly explain the behaviour:
- pass the
$myField->excerpt(140)
as an argument to my method
- inside my method I do a safety check to make sure
$myField
is longer than the excerpt
- if safety check is true return the string of
$myField
starting at 141
Any ideas or feedback appreciated.
I don’t have the time right now to read through your complete post, but hust a quick reminder, if you don’t specify any parameters, excerpt()
counts characters not words.
@textnixe
I know, my method counts characters, too, as it uses the str::substr
helper
But I just noticed that my method excerptRest
is actually safe. Even if excerpt()
returns inconsistent string lengths, my method just follows this behaviour as it reuses theexcerpt()
output.
It might be still interesting to understand where this inconsistency (split full word < > respect a full word) of excerpt()
is coming from…but I guess with the team working on Kirby V3 this is low priority 