Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jinja2 template char limit

Tags:

jinja2

in {{blog.content}} I want to limit the viewer to see only 50 char at most, how can I do that using jinja2?

After searching through their documentation I have found that {{ s|autolink[ length[ nofollow]] }} has a length property but it will make it auto link! Which I don't want it to be.

like image 946
sadaf2605 Avatar asked Dec 21 '22 09:12

sadaf2605


2 Answers

Have you tried the python slice notation?

{{ blog.content[:50] }}
like image 193
Paul Collingwood Avatar answered Mar 24 '23 01:03

Paul Collingwood


The documentation for jinja2 says to use {{ blog.content|truncate(50) }}. Thats what I have been using thus far.

You can find the docs for template here.

like image 35
vt-cwalker Avatar answered Mar 24 '23 01:03

vt-cwalker