Hi Pavel!

I'm not sure if this is what you need, but:

1. If you create a value in website tree, for example by using the JCR-Browser, 
you can simply do something like:
    ${model.siteRoot.myConstants.myCoolValue}
(assuming you created a node-data called "myConstants" under the site's root 
node, and added a property "myCoolValue" to it).

2. We found that we wanted something like "site variables" - in particular we 
use them to define colors which we then use in our theme's CSS files, but also 
for other purposes.
- In order to achieve this we extended the "Site" class 
(info.magnolia.module.templatingkit.sites.Site) and added a new configuration 
for "variables" - something like:

public class MySiteModel extends info.magnolia.module.templatingkit.sites.Site {
        /**
         * Holds site variables
         */
        Map<String,String> variables = new HashMap<String,String>();
        /**
         * Returns the named site variable, or null if not found
         * @param id the variable name
         * @return the variable value, a String
         */
        public String var(String id){
                return variables.get(id);
        }
        /**
         * Returns the named site variable, or the supplied default value if 
not found
         * @param id the variable name
         * @param defaultVal the default value
         * @return the variable value, a String
         */
        public String var(String id,String defaultVal){
                String it = variables.get(id);
                if (it==null)
                        return defaultVal;
                return it;
        }
        /**
         * @return the variables
         */
        public Map<String, String> getVariables() {
                return variables;
        }
        /**
         * @param variables the variables to set
         */
        public void setVariables(Map<String, String> variables) {
                this.variables = variables;
        }
        public void addVariable(String id,String val){
                this.variables.put(id,val);
        }
        public void putVariable(String id,String val){
                this.variables.put(id,val);
        }
}

We set our custom class to be the class of our site definitions, and then we 
can use something like:
    ${model.site.var("myvariablename")}
to retrieve our values.

We use this for all kinds of things that should be configured by Admins, but 
shouldn't really be part of the content and editable by "normal" editors.

Regards from Vienna,

Richard


-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] 
Im Auftrag von Pavel Škop
Gesendet: Freitag, 21. Jänner 2011 11:01
An: Magnolia User-List
Betreff: [magnolia-user] Constant in magnolia tree


Hi,
I like to store some technical constant in magnolia tree (to manage it by 
adminCentral).
How can I access this constant from freemarker template (some query to magnolia 
tree from root node..) ?
Pavel Skop


----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------





----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to