Ask Your Question
1

cannot add templatetags

asked 2011-08-10 07:56:17 -0600

Samuel gravatar image

I have created a new template "mytemplate.html" extending "two_column_body.html". It was working until I try to use custom tags. I have created the file askbot/templatetags/mytags.py containing for instance :

@register.simple_tag
def mytag():
...

In "mytemplate.html" I add :

...
{% load mytags %}
 <label>{% mytag %}</label>
...

and I get this messages in the logs :

/usr/local/virtualenv/askbot/lib/python2.6/site-packages/askbot/middleware/pagesize.py TIME: 2011-08-10 14:31:34,457 MSG: pagesize.py:process_exception:44 <class 'jinja2.exceptions.TemplateSyntaxError'>
/usr/local/virtualenv/askbot/lib/python2.6/site-packages/askbot/middleware/pagesize.py TIME: 2011-08-10 14:31:34,457 MSG: pagesize.py:process_exception:45 Encountered unknown tag 'mytag'. Jinja was looking for the following tags: 'endblock'. The innermost block that needs to be closed is 'block'.

Any idea?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2011-08-10 08:12:54 -0600

Evgeny gravatar image

In Jinja2 template tags are harder to add, but almost in all cases they can be replaced with a macro.

http://jinja.pocoo.org/docs/templates/#macros

There are lots of macros in file askbot/skins/default/templates/macros.html and examples of use are in many places, for example in a template question.html.

Do you need to add extra context variables, right now you can add them via a custom template context processor, we can also add extra_context parameters to the views. Could you explain in more detail what you are trying to do?

edit flag offensive delete link more

Comments

well.... I have forked and highly refactored the project Speeqe in order to be able to plug it to askbot. At this stage my askbot instance is able to list chatrooms in a jabber server and has a web chat client embedded. It is a light beta version of chat.stackoverflow. Now I have added a new tab (chat) in the main-nav to list the chatrooms. Imagine that my template in my initial question lists the chatrooms. The tags used managed the connection to the xmpp server. Let me know if you are interested.
Samuel gravatar imageSamuel ( 2011-08-10 08:59:44 -0600 )edit
Samuel gravatar imageSamuel ( 2011-08-10 11:16:14 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-08-10 07:56:17 -0600

Seen: 669 times

Last updated: Aug 10 '11