OK, well, I started calling parser.next_token() instead of
parser.delete_first_token() and my problems are mysteriously solved...
so far. Probably there was a boneheaded syntax error somewhere I
accidentally cleared up while fiddling. Still, any feedback is
appreciated... templatetags are great and I'm just finishing up a nice
little library for working with particular tree structures of
arbitrary depth, the crown of which is this nice little recursive
control structure I'm making. Everything else has been great, the
parser kills me!

On Nov 29, 9:37 pm, stevedegrace <[EMAIL PROTECTED]> wrote:
> I have a weird problem. (I'm using Django 1.0.2, Python version 2.5.2
> on Ubuntu 8.10). Say I have a template like this:
>
> """
> {% sometag %}
> Some stuff
> {% someothertag %}
> Some more stuff
> {% yetanothertag %}
> Last stuff
> {% endsometag %}
> """
> My template tag function looks something like this:
>
> @register.tag(name="sometag")
> def do_sometag(parser, token):
>     nodelist1 = parser.parse(('someothertag',' yetanothertag',
> 'endsometag'))
>     parser.delete_first_token()
>     nodelist2 = parser.parse(('someothertag',' yetanothertag',
> 'endsometag'))
>     parser.delete_first_token()
>     # ... do some stuff ... no point returning a node, not going to
> get that far...
>
> This is just distilling my problem down. My actual project is more
> complicated, but the above code fails exactly as advertised for me,
> and I would need the above to work for what I want to work. What will
> happen is that the parser is happy as anything to do the first call to
> parse. On the second call to parse, no matter what tag is next in the
> template, an exception is raise. In the template above, where
> someothertag is next, I will get:
>
> Exception Type:         TemplateSyntaxError
> Exception Value:
>
> Invalid block tag: 'yetanothertag'
>
> Exception Location:     /usr/lib/python2.5/site-packages/django/template/
> __init__.py in invalid_block_tag, line 333
>
> Like, what the hell. Can anyone explain to me why I can't call parse
> more than once and pick up more pieces? What am I missing here? I've
> tried copying what the if tag does for its else clause (the if-else-
> endif set works) but again the parser chokes the second time it is
> called. Can someone make my headache go away? :) What I ultimately
> want to do is loop over a set of tags, saving up the NodeLists, until
> the end tag is encountered.
>
> Thanks,
>
> Stephen
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to