Alexander Solonik Alexander Solonik - 14 days ago 7
Twig Question

How does excerpt work in bolt and what are the accepted parameters?

I was just going through the default twig theme files in bolt CMS and came across the following lines of code:

<p>{{ record.excerpt(300, false, search|default('')) }}</p>

Now i checked the bolt docs to see how the excerpt functions works and i came across the following lines of code:

Create a short excerpt from var, without HTML formatting, restricted
by length characters. var can be a 'record' object, a single value
from a 'record' or a regular string.*

But in the above peice of code there is a third parameter being passed which i dont quite understand I.E.
, Also what is
for ?

I was just glancing though the cheetsheet in the bolt docs HERE , but the definition listed there does't match the usage , can somebody clarify how this function works ??


Ah, this is another funky part of Twig. It a "filter" that just tells Twig, that if a variable doesn't exist, give it a default value, e.g.

{{ var|default('var is not defined') }}

In the example you posted, that would just set the value to an empty string if it doesn't exist.

More information on that filter