0

I am using "truncatechars" when I want to display texts with more than 600 chars.

What i am doing is: when texts have more than 600 chars I truncate chars to show just a small text, and than I have a "show more" button to show all text.

 {{ad.description|truncatechars:"600"}} {% if ad.description|length > 150 %}<a href="#">ver mais...</a> {% endif %}

How can I remove the "truncatechars" property dynamically?

2
  • are you using jquery?
    – karthikr
    Apr 4, 2013 at 21:46
  • you dont need the truncatechars here. It would get too complicated. I would just go with a simple jquery solution. Checkout the answer
    – karthikr
    Apr 4, 2013 at 21:55

2 Answers 2

2

You do not have to use truncatechars. You can do a pure javascript/jquery implementation of this functionality.

There are plugins you could use.

OR

If you were to implement it yourself, check this link out

All you have to do is add a wrapper around {{ad.description|safe}}

0
1

If you want to 'show more' then you shouldn't use django's template tags at all as they are rendered on the server side. This means that the client (browser) will never get anything more then the first 600 characters. Instead do it with javascript. There are lots of plugins & tutorials that handle this (here, here & here for example)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.