On Monday, 30 April 2012 09:03:56 UTC+1, 95felipe wrote:
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_htmlHere, 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 could simply instantiate and render a template.Template object with the content of `spam_html` and the existing context:
spam_tpl = template.Template(spam_html)
return spam_tpl.render(context)
--
DR.
-- 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/-/EInWLvpkZL0J.
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