First time here? Check out the FAQ!
0

Introduce Custom Tags

I see the templatetags folder inside askbot. I have been adding all the new apps that I build on top of askbot under askbot folder.

I have my main application askbot and inside that I have experiments folder as another application.

I used askbot's utils module to introduce the tags of my application. I used the decorators.py.

def set_experiment_user(view_func):
    '''Decorator for setting the WebUser for use with ab split testing assumes
    first argument is the request object'''
    @functools.wraps(view_func)
    def decorator(request, *args, **kwargs):
        WebUser(request).confirm_human()
        return view_func(request, *args, **kwargs)
    return decorator

Then in my view

@decorators.set_experiment_user
def ask_widget(request, widget_id):

and in the template, I have done the following:

{% import "macros.html" as macros %}

{% load experiments %}
{% experiment experiment_name top_contributors %}
{% if contributors and settings.SIDEBAR_MAIN_SHOW_AVATARS %}
    {% include "widgets/contributors.html" %}
{% endif %}
{% endexperiments %}

But I get the following error: But I get the following error:

Encountered unknown tag 'experiment'.
Request Method: GET
Request URL:    http://localhost:8001/questions/
Django Version:  1.4.10
Exception Type:  TemplateSyntaxError
Exception Value:    
Encountered unknown tag 'experiment'.
Exception Location: ../askbot/templates/main_page/sidebar.html in template, line 4

this means that it doesn't understand the "experiment" template tag, I read the following url since I have 'django.core.context_processors.request', in settings.py I didn't think i have to do anything to make sure custom templates to be registered.

https://docs.djangoproject.com/en/1.4/howto/custom-template-tags/

It would be a great help if you could provide any insight on this.

I also have utils.py in my experiment module should I be my set_experiment into that instead of askbot's utils.

SocialQA's avatar
265
SocialQA
asked 2014-01-12 09:01:07 -0600, updated 2014-01-12 09:01:56 -0600
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

0

We are using Jinja2 templates, therefore please refer to their documentation. Also, in Jinja2 it's easier to write custom template filters rather than template tags, perhaps you could achieve your goal that way.

Evgeny's avatar
13.2k
Evgeny
answered 2014-01-12 11:08:15 -0600
edit flag offensive 0 remove flag delete link

Comments

but if I want to do this was it should work right? I don't want to deal with Jinja as want to avoid as much as possible.

SocialQA's avatar SocialQA (2014-01-12 14:50:22 -0600) edit
add a comment see more comments