Monday, April 30, 2012

Parse Custom html in custom template tags, django 1.4

Hi. I've been struggling with this problem the whole night and just couldn't find any solution. I've tried reverse engineering the template/base.py file, but things are getting ugly. :S

How can I, inside a custom tag class (template.Node), make the parser render a snippet of html with tags in it? For example:

@register.tag(name='addspam')
class AddSpam(template.Node):
   
def __init__(self, parser, token): ...
   
def render(self, context):
        spam_html
= "SPAM { any_tag_here } SPAM"
       
return spam_html

Here, AddSpam, when 'called', returns 'SPAM { any_tag_here } SPAM', without rendering the any_tag_here.That's obviously the predictable, but how can I change the return value so that any_tag_here is rendered as if it was 'native'? Are there any methods using the context and the parser that I could use? Thanks!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/7MfK_zBy_mgJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment