Read more link

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#myapp/templatetags/blog_filters.py

from django import template
register = template.Library()
import settings

@register.filter('read_more')
def read_more(body, absolute_url):
	if '<!--more-->' in body:
		return body[:body.find('<!--more-->')]+'<a href="'+str(absolute_url)+'">'+str(settings.READ_MORE_TEXT)+'</a>'
	else:
		return body

More like this

  1. Hyperlink list filter by lifefloatsby 5 years, 4 months ago
  2. Template filter to convert timecodes into links by justin_h 3 years, 8 months ago
  3. Tags & filters for rendering search results by exogen 5 years, 2 months ago
  4. email_links by sansmojo 5 years, 11 months ago
  5. Create short URL redirects for site urls. by matt.geek.nz 4 years, 3 months ago

Comments

svetlyak (on September 4, 2008):

I'll rewrite this as:

def read_more(body, absolute_url):
    pos = body.find('<!--more-->')
    if pos == -1:
        return body
    else:
        return '<a href="%s">%s</a>' % (body[:pos], settings.READ_MORE_TEXT))

#

(Forgotten your password?)