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.

Reply via email to