Re: [mezzanine-users] Easy way to grab data from an installed app in the templates

2015-07-16 Thread Brandon Keith Biggs

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 %} #}
h2My text!/h2
pHere is my text and the variable is: {{ my_text }}/p

pHere is my lovely text. Here are the important links:/p

h2Links/h2
ul
lia href=/admin/Log in to the admin interface/a/li
lia 
href=http://mezzanine.jupo.org/docs/content-architecture.html;Creating 
custom page types/a/li
lia 
href=http://mezzanine.jupo.org/docs/frequently-asked-questions.html#templates;Modifying 
HTML templates/a/li
lia 
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
lia 
href=http://mezzanine.jupo.org/docs/frequently-asked-questions.html;Other 
frequently asked questions/a/li
lia 
href=http://mezzanine.jupo.org/docs/configuration.html#default-settings;Full 
list of settings/a/li
lia 
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 
brandonkeithbi...@gmail.com mailto:brandonkeithbi...@gmail.com 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 %}
h1my 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 mezzanine-users+unsubscr...@googlegroups.com
mailto:mezzanine-users+unsubscr...@googlegroups.com.
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 mezzanine-users+unsubscr...@googlegroups.com 
mailto:mezzanine-users+unsubscr...@googlegroups.com.

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 mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] Easy way to grab data from an installed app in the templates

2015-07-16 Thread Eduardo Rivas
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 mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] Easy way to grab data from an installed app in the templates

2015-07-16 Thread Brandon Keith Biggs

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 mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] Easy way to grab data from an installed app in the templates

2015-07-15 Thread Brandon Keith Biggs

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 %}
h1my 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 mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] Easy way to grab data from an installed app in the templates

2015-07-15 Thread Stephen McDonald
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 
brandonkeithbi...@gmail.com 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 %}
 h1my 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 mezzanine-users+unsubscr...@googlegroups.com.
 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 mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] Easy way to grab data from an installed app in the templates

2015-07-15 Thread Brandon Keith Biggs

Hello,
How do you call the function in a block? Because for my index I have:
{% block main %}
{% blocktrans %}
h1my text/h1
{% where I want the function %}
{{ where I want the variable }}
{% endblocktrans %}
{% endblock %}

Thanks,

Brandon Keith Biggs http://www.brandonkeithbiggs.com/
On 7/16/2015 12:23 AM, Eduardo Rivas wrote:
As an alternative, you can also use SingletonAdmin and a template tag 
to make model data available anywhere in the site. Josh wrote about it 
and I follow this pattern all the time: 
http://bitofpixels.com/blog/on-singletonadmins-and-sitewidecontent-editing-sitewide-content-in-mezzanines-admin/.




--
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 mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] Easy way to grab data from an installed app in the templates

2015-07-15 Thread Eduardo Rivas
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 %}
h1my 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 mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] Easy way to grab data from an installed app in the templates

2015-07-15 Thread Brandon Keith Biggs

Hello,
I think I did this exactly how you said, but in my index.html nothing 
shows up. Here is what I have:

my_app/defaults.py

from mezzanine.conf import register_setting

register_setting(name='test_text', default=Hello world)
register_setting(name=TEMPLATE_ACCESSIBLE_SETTINGS, append=True, 
default=(test_text,))



my_theme/templates/index.html

{% extends base.html %}
... all defaults
{% block main %}
{% blocktrans %}
h2My text!/h2
pHere is my text and the variable is: {{ settings.test_text }}/p
{% endblocktrans %}
{% endblock %}


I get the first part of the text, but the variable is not there at all.
thanks,

Brandon Keith Biggs http://www.brandonkeithbiggs.com/
On 7/16/2015 12:12 AM, Danny wrote:

On 16/07/2015 7:30 AM, Brandon Keith Biggs wrote:

Hello,
Is there an easy way to create template variables and functions 
without modifying the site urls?

Perhaps in mezzanine_tags or something?
A variable like
{{ mezzanine.my_app.my_variable }}
would be fine.
Is this what page can help with? I want to use these variables in my 
custom theme.

thank you,


I think what you might be looking for is to create your own setting, 
and then use it in a template, right?


http://mezzanine.readthedocs.org/en/latest/configuration.html

Basically:
In your app, create a defaults.py, and use register_setting() to 
create the variable you want.
It can be editable in the admin if you like, or just configurable via 
settings/local_settings.py


Then you'll need to update TEMPLATE_ACCESSIBLE_SETTINGS so that your 
new setting is listed there,

making it accessible within templates.

And then you should be able to just reference {{settings.variable}} in 
any template that has mezzanine_tags loaded.


For example, I have in my app's defaults.py:

register_setting(
name=SOCIAL_FACEBOOK,
description=Link to Facebook Page. Include http prefix.,
editable=True,
default=,
)
register_setting(
name=TEMPLATE_ACCESSIBLE_SETTINGS,
append=True,
default=(SOCIAL_FACEBOOK,),
)

And then in my base.html:

{% load mezzanine_tags ... %}
...
{% if settings.SOCIAL_FACEBOOK %}
a href={{ settings.SOCIAL_FACEBOOK }}Facebook/a
{% endif %}

So this allows me to add a link to my Facebook page in the admin 
(Settings section) and have that link show up on every page of the 
site via the base.html template.


Seeya. Danny.


--
*Danny Sag*
Chairperson
Round World Events SA, Inc
City of Small Gods Terry Pratchett Fan Club - 
http://cityofsmallgods.org.au


*Nullus Anxietas VI - The Australian Discworld Convention* - 
http://ausdwcon.org

The Discworld Grand Tour - Adelaide SA, August 4-6, 2017
--
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 mezzanine-users+unsubscr...@googlegroups.com 
mailto:mezzanine-users+unsubscr...@googlegroups.com.

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 mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] Easy way to grab data from an installed app in the templates

2015-07-15 Thread Brandon Keith Biggs

Hello,
That was totally the problem!

I would like to be able to keep the translation ability for the 
variables, is there any way to use a filter on the text before it goes 
into blocktrans?

I tried doing something like:

my_app/templatetags/module.py
from django import template
register = template.Library()

my_theme/templates/index.html
{% load shortcodes %}
...
{% block main|test_filter %}
{% blocktrans %}
h2My text!/h2
pI like flowers, apples, flowers, oranges, flowers and flowers!/p
{% endblocktrans %}
{% endblock %}

and nothing shows up on the page...
I've already got a filter I am using for richtext, so I'll just transfer 
that over if I can.


Other question, if I'm not to use html tags in the translated area, what 
do I use? Do I just put a whole lot of blocktrans tags in my html tags?

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 %}
h1my 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 mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[mezzanine-users] Easy way to grab data from an installed app in the templates

2015-07-15 Thread Brandon Keith Biggs

Hello,
Is there an easy way to create template variables and functions without 
modifying the site urls?

Perhaps in mezzanine_tags or something?
A variable like
{{ mezzanine.my_app.my_variable }}
would be fine.
Is this what page can help with? I want to use these variables in my 
custom theme.

thank you,

--
Brandon Keith Biggs http://www.brandonkeithbiggs.com/

--
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 mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] Easy way to grab data from an installed app in the templates

2015-07-15 Thread Danny

On 16/07/2015 7:30 AM, Brandon Keith Biggs wrote:

Hello,
Is there an easy way to create template variables and functions 
without modifying the site urls?

Perhaps in mezzanine_tags or something?
A variable like
{{ mezzanine.my_app.my_variable }}
would be fine.
Is this what page can help with? I want to use these variables in my 
custom theme.

thank you,


I think what you might be looking for is to create your own setting, and 
then use it in a template, right?


http://mezzanine.readthedocs.org/en/latest/configuration.html

Basically:
In your app, create a defaults.py, and use register_setting() to create 
the variable you want.
It can be editable in the admin if you like, or just configurable via 
settings/local_settings.py


Then you'll need to update TEMPLATE_ACCESSIBLE_SETTINGS so that your new 
setting is listed there,

making it accessible within templates.

And then you should be able to just reference {{settings.variable}} in 
any template that has mezzanine_tags loaded.


For example, I have in my app's defaults.py:

register_setting(
name=SOCIAL_FACEBOOK,
description=Link to Facebook Page. Include http prefix.,
editable=True,
default=,
)
register_setting(
name=TEMPLATE_ACCESSIBLE_SETTINGS,
append=True,
default=(SOCIAL_FACEBOOK,),
)

And then in my base.html:

{% load mezzanine_tags ... %}
...
{% if settings.SOCIAL_FACEBOOK %}
a href={{ settings.SOCIAL_FACEBOOK }}Facebook/a
{% endif %}

So this allows me to add a link to my Facebook page in the admin 
(Settings section) and have that link show up on every page of the site 
via the base.html template.


Seeya. Danny.


--
*Danny Sag*
Chairperson
Round World Events SA, Inc
City of Small Gods Terry Pratchett Fan Club - http://cityofsmallgods.org.au

*Nullus Anxietas VI - The Australian Discworld Convention* - 
http://ausdwcon.org

The Discworld Grand Tour - Adelaide SA, August 4-6, 2017

--
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 mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] Easy way to grab data from an installed app in the templates

2015-07-15 Thread Eduardo Rivas
As an alternative, you can also use SingletonAdmin and a template tag to 
make model data available anywhere in the site. Josh wrote about it and 
I follow this pattern all the time: 
http://bitofpixels.com/blog/on-singletonadmins-and-sitewidecontent-editing-sitewide-content-in-mezzanines-admin/.


--
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 mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.