Hello,
I figured everything out. I was passing the wrong thing into my function (spent too much time figuring out tags and forgot how I wrote it.) Now everything works. I am wondering if there is any examples of how to use the different mezzanine tags with a full index file and templatetags module? I get an error when running some of them and they have to do with wrong arguments or something and I have no idea why.
thanks,

Brandon Keith Biggs <http://www.brandonkeithbiggs.com/>
On 7/17/2015 1:09 AM, Brandon Keith Biggs wrote:
Hello,
I am just not having a good time with these tags!!! I don't know if I'm not reading the errors correctly, but I can't figure out at all what is happening from the messages.

I have a dict and I want to be able to grab a value from that dict which is a function. So the dict looks like {'name': function} and that returns a message. added_shortcodes is the dict and code_name is the name of the code we are getting from the dict. The *args and **kwargs are being passed to the function retrieved from the dict.

my_app/templatetags/my_tags.py
from mezzanine import template
register = template.Library()
@register.assignment_tag
def codes(code_name, *args, **kwargs):
    return added_shortcodes[code_name](*args, **kwargs)

my_theme/templates/index.html
{% load my_tags %}
...
{% block main %}
{# {% blocktrans %} #}
{% codes "birthday" "brandon" as result %}
<h2>My text!</h2>
<p>Here is my text and the variable is: {{ result }}</p>
{% endblock %}

AttributeError at /
'SafeText' object has no attribute 'get'
Request Method:
GET

Thanks,

Brandon Keith Biggs <http://www.brandonkeithbiggs.com/>
On 7/17/2015 12:26 AM, Brandon Keith Biggs wrote:
Hello,
So the document namespace doesn't go into the block? That worked!
thank you,

Brandon Keith Biggs <http://www.brandonkeithbiggs.com/>
On 7/16/2015 10:41 PM, Eduardo Rivas wrote:
Yeah, a server restart is required when you create new template tags for Django to pick them up.

As for your template code, try putting {% test_text "Flowers are nice" as my_text %} inside the block you want to use the variable (in your case: {% block main %}).




--
You received this message because you are subscribed to the Google Groups "Mezzanine 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to