ventojs / vento

🌬 A template engine for Deno & Node
https://vento.js.org/
MIT License
212 stars 12 forks source link

Is truncating possible? #42

Closed tjaynl closed 8 months ago

tjaynl commented 8 months ago

So i'm trying to truncate a portion of a text.

I tried this:

{{ content |> md |> truncate(20) }}

While this line does seem to work the output is not giving as in there is no content output but also no error. Am i doing it wrong?

oscarotero commented 8 months ago

The code {{ "Hello" |> truncate(2) }} is compiled as "Hello"?.truncate?.(2), which returns undefined. Maybe it should be compiled to "Hello"?.truncate(2) so it would output an error... 🤔

truncate function doesn't exist (unless it's register as a filter). You can use substring for that:

{{ content |> md |> substring(0, 20) }}
tjaynl commented 8 months ago

Thank you for giving me an alternative, didn't know that could be used.