I have templatetags/custom_format.py, and in it I have
do_custom_format_string1, do_custom_format_string2. I placed the
template tags
one after another, insdie my html page like this:
{% for a_object in object_list %}
{% load custom_format %}
{% custom_format_string1 a_object.3 %}
<td>{{split_string_data1}}</td>
{% end_custom_format_string1 %)
{% custom_format_string2 a_object.4 %}
<td>{{split_string_data2}}</td>
{% end_custom_format_string2 %)
{% endfor %}
custom_format.py:
from django import template
#from django.template import Variable
from django.template import resolve_variable
register = template.Library()
@register.tag(name="custom_format_sting1")
def do_custom_format_sting1(parser, token):
nodelist = parser.parse(('end_custom_format_sting1',))
tag_name, data_to_split = token.split_contents()
parser.delete_first_token()
return CustomFormatString1Node(nodelist, data_to_split)
class CustomFormatString1Node(template.Node):
def __init__(self, nodelist, data_to_split):
self.nodelist = nodelist
self.data_to_split = data_to_split
def render(self, context):
actual_data = resolve_variable(self.data_to_split, context)
datalist = actual_data.split(',')
context['split_string_data1'] = "".join(datalist)
output = self.nodelist.render(context)
return output.custom_format_sting1()
@register.tag(name="custom_format_sting2")
def do_custom_format_sting2(parser, token):
nodelist = parser.parse(('end_custom_format_sting2',))
tag_name, data_to_split = token.split_contents()
parser.delete_first_token()
return CustomFormatString2Node(nodelist, data_to_split)
class CustomFormatString2Node(template.Node):
def __init__(self, nodelist, data_to_split):
self.nodelist = nodelist
self.data_to_split = data_to_split
def render(self, context):
actual_data = resolve_variable(self.data_to_split, context)
datalist = actual_data.split('-')
context['split_string_data2'] = "".join(datalist)
output = self.nodelist.render(context)
return output.custom_format_sting2()
Error I am getting:
Exception Type: TemplateSyntaxError
Exception Value: Invalid block tag: 'custom_format_string1'
error at html file:
{% custom_format_string1 a_object.3 %}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---