ventojs / vento

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

Is truncating possible? #42

Closed tjaynl closed 4 months ago

tjaynl commented 4 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 4 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 4 months ago

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