Hello,
No, I needed to restart my server for some reason...
I got it to not give an error, but now it is still hiding my variable in the
{% block main %}
{% endblock %}
tags. Here is what I have:
my_app/templatetags/my_tags.py
from mezzanine import template
register = template.Library()
@register.assignment_tag
def test_text(format_string="I like cheese"):
return format_string
my_theme/templates/index.html
{% extends "base.html" %}
{% load i18n %}
{% load my_tags %}
{% test_text "Flowers are nice" as my_text %}
{% block meta_title %}{% trans "Home" %}{% endblock %}
{% block title %}{% trans "Home" %}{% endblock %}
{% block breadcrumb_menu %}
<li class="active">{% trans "Home" %}</li>
{% endblock %}
{% block main %}
{# {% blocktrans %} #}
<h2>My text!</h2>
<p>Here is my text and the variable is: {{ my_text }}</p>
<p>Here is my lovely text. Here are the important links:</p>
<h2>Links</h2>
<ul>
<li><a href="/admin/">Log in to the admin interface</a></li>
<li><a
href="http://mezzanine.jupo.org/docs/content-architecture.html">Creating
custom page types</a></li>
<li><a
href="http://mezzanine.jupo.org/docs/frequently-asked-questions.html#templates">Modifying
HTML templates</a></li>
<li><a
href="http://mezzanine.jupo.org/docs/frequently-asked-questions.html#why-isn-t-the-homepage-a-page-object-i-can-edit-via-the-admin">Changing
this homepage</a></li>
<li><a
href="http://mezzanine.jupo.org/docs/frequently-asked-questions.html">Other
frequently asked questions</a></li>
<li><a
href="http://mezzanine.jupo.org/docs/configuration.html#default-settings">Full
list of settings</a></li>
<li><a
href="http://mezzanine.jupo.org/docs/deployment.html">Deploying to a
production server</a></li>
</ul>
{# {% endblocktrans %} #}
{% endblock %}
The variable does not show up at all.
thanks,
Brandon Keith Biggs <http://www.brandonkeithbiggs.com/>
On 7/16/2015 6:06 AM, Stephen McDonald wrote:
You're probably missing an empty __init__.py file:
https://docs.djangoproject.com/en/1.8/howto/custom-template-tags/#code-layout
On Thu, Jul 16, 2015 at 12:00 PM, Brandon Keith Biggs
<[email protected] <mailto:[email protected]>> wrote:
Hello,
I can't get this method to work. Here is what I have:
my_app/script_module.py
from mezzanine import template
register = template.Library()
@register.as_tag
def test_text():
return "Hello world"
my_theme/templates/index.html
{% extends "base.html" %}
{% load i18n %}
{% test_text %}
I get the error:
TemplateSyntaxError at /
Invalid block tag: 'test_text'
I then try adding in index.html:
{% extends "base.html" %}
{% load i18n %}
{% load my_app %}
{% test_text %}
But then get:
TemplateSyntaxError at /
'my_app' is not a valid tag library:
So then when I put
script_module.py
into
my_app/templatetags/my_script.py
I still get the same error.
thanks,
Brandon Keith Biggs <http://www.brandonkeithbiggs.com/>
On 7/16/2015 1:18 AM, Eduardo Rivas wrote:
That should work without issue, though I generally like to bundle
all the "as" tags on top of the block.
{% block main %}
{% get_sitewide_content as sitewide %}
<h1>my text</h1>
{{ sitewide.foobar }}
{% endblock %}
Also, be careful with the blocktrans tag, you need to explicitly
bind any variable you want to use inside them. You should also
avoid including HTML tags inside them to prevent poluting the
gettext catalog with markup
https://docs.djangoproject.com/en/1.7/topics/i18n/translation/#blocktrans-template-tag.
--
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]
<mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.
--
Stephen McDonald
http://jupo.org
--
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]
<mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.
--
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.