Example of introducing tags

asked 2014-01-16 10:58:13 -0500

SocialQA gravatar image

updated 2014-01-16 11:02:43 -0500

I have added a module with templetags and due to jinja its really hard to figure out how i can simply do something like this:

{% experiment "signuptext" variants "control,free,trial" %}

{% if contributors and settings.SIDEBAR_MAIN_SHOW_AVATARS %}
    {% include "widgets/contributors.html" %}
{% endif %}

because moment I try to add {% experiment "signuptext" variants "control,free,trial" %} it complains saying:

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 6
Python Executable:  /../..//bin/python
Python Version: 2.7.5

Here is the implementation of the experiment:

def experiment(parser, token):
        tag_name, exp_name, variants_label, variantstring = token.split_contents()
    except ValueError:
        raise template.TemplateSyntaxError, '%r tag requires exactly three arguments, e.g. {% experiment "signuptext" variants "control,free,trial" %}' % token.contents.split()[0]

    return ExperimentNode(exp_name.strip("\"'"), variantstring.strip("\"'").split(","))
edit retag flag offensive close merge delete



Could you point, please to the implementation of "experiment"? Is it a third-party django app?

Evgeny gravatar image Evgeny  ( 2014-01-16 11:00:54 -0500 )edit

@Evgeny just updated the question thanks,

SocialQA gravatar image SocialQA  ( 2014-01-16 11:03:09 -0500 )edit

@Evgeny This is an implementation i did since no body answer my question in askbot forum. So here is what I am trying to do I posted the question in stackoverflow. http://stackoverflow.com/questions/21142591/django-lean-introducing-new-template-tags since I couldn't figure out above mention problem I ended up building a simple version but same issue. So I guess if you can provide an answer to stackoverflow question that would be great. Or if you can provide the solution for above thats fine too. THanks

SocialQA gravatar image SocialQA  ( 2014-01-16 11:05:58 -0500 )edit

Sorry, I can't answer your question directly right now, but here you don't have a choice but read the Jinja2 documentation about the template tags and filters. If you can replace that implementation as template filter, then that will be easy in Jinja2.

Evgeny gravatar image Evgeny  ( 2014-01-16 11:15:18 -0500 )edit