How to accomplish post excerpt

23 views
Skip to first unread message

ola.d...@gmail.com

unread,
Jan 14, 2013, 11:52:49 AM1/14/13
to web...@googlegroups.com
{{ for post in posts:}}
   <h2>
     <a href="{{=URL(r=request,f='view_post',args=post.id)}}">
       {{=post.title}}
     </a>
   </h2>
{{=WIKI(post.body|truncate:30)}}
{{pass}}

Thanks in avance. something similar to Django |truncate:x

Niphlod

unread,
Jan 14, 2013, 12:02:56 PM1/14/13
to web...@googlegroups.com
if post.body is a string, you can do post.body[:30]  like you would do with a normal python string. You can't get fancy with a post.body[:27] + '...' just for the sake of being "polite.

The problem in your code is that you're "truncating" a source of something that needs to be truncated at the right position.....e.g. if you're inside a blockquote and you don't close the "quote", you'll be left with an "uncorrect" representation of the truncated markmin .....

e.g.

- a list
-- ``web2py
lorem ipsum etcetcetc
...
....
``:code


if your truncation leaves the last line out, the generated HTML might not be correct.

ola.d...@gmail.com

unread,
Jan 14, 2013, 12:08:54 PM1/14/13
to web...@googlegroups.com
Thanks for the quick response. quite helpful. 
Reply all
Reply to author
Forward
0 new messages