Personal tools
Contact Us 24/7 > 1 866.SIX FEET
Sections

Skip to content. | Skip to navigation

Home > Blog > How to use Variables in Diazo

Blog

How to use Variables in Diazo

written by Chrissy Wainwright on Thursday November 13, 2014
Comments | Filed under: , ,

Variables can be used in your Diazo rules.xml from TAL expressions set in your theme. These variables are defined in your theme's manifest.cfg like so:

[theme:parameters]
portal_url = portal_state/portal_url
ajax_load = python: 'ajax_load' in request.form
anon_user = portal_state/anonymous

These are some commonly used variables. Just like TAL, they use path expressions by default, but python: or string: can be specified.Diazo concept graphic

If the parameters were set directly in the manifest.cfg, you will need to reactivate the theme in the Theming control panel (deactivate, then activate). The parameters can also be set in the control panel's Advanced Settings tab. Available variables that can be used within the expressions are context, request, portal, portal_state, and context_state.

Use in rules.xml

Use variables prefixed with $. If used in HTML within a rule, the variable also needs to be wrapped in curly braces:

<drop css:content="#portal-breadcrumbs"
      if-path="$portal_url"/>

<replace css:theme="#sitesearch">
  <form action="{$portal_url}/@@search" method="post">
  ...
</replace>

Simple condition expressions can also be done in the rules using the variables:

<drop css:theme=".manageLink"
      if="$role != 'administrator'"/>

 

I hope this gives you a brief understanding of how to apply variables in your Diazo theme. You can learn more at Diazo.org and also find more trainings like this one at sixfeetup.com/plone-cms/plone-how-to.

Like what you've read? Be sure to sign up for our weekly Plone & Python How-To digests.

 
Posted by keul on Nov 17, 2014 03:36 AM
Nice post, just a behavior I found: unluckily you can re-use already defines variables in expressions defined later. So: it's not working as tal:define commonly works in TAL.
Add comment

You can add a comment by filling out the form below. Plain text formatting.

puzzle

Next Steps


Select a type of support:

Contact our sales team

First name:
Last name:
Email:
Phone Number:
Message:
Fight spam:
What is + ?
 
Call Us 1 866.SIX FEET
Sections