问题
I have numerous custom variables in Alfresco's alfresco-global.properties file that I'd like to use throughout various freemarker ftl files as well as the various YUI files, which will greatly alter the behavior of Share and how it displays information.
I have the property values accessible through various javascript calls (for example, getNetworkName()
will return the custom app.network.name
variable set in the properties), but I am uncertain of how I'd expose these javascript functions to either freemarker or the YUI files, or if I even need to, as opposed to just accessing the variables directly.
回答1:
If you have defined global variables and functions you don't need to do anything special to access them from YUI.
You can optionally do something like this to take advantage of YUI's sandboxing ability so that each sandbox can't affect the other by changing the global configuration:
YUI_config = {
app: {
network: {
name: 'foo' // or getNetworkName()
}
}
};
YUI().use('node', function (Y) {
console.log(Y.config.app.network.name); // foo
Y.config.app.network.name = 'bar';
});
YUI().use('tabview', function (Y) {
console.log(Y.config.app.network.name); // still foo!
});
来源:https://stackoverflow.com/questions/11366978/how-to-access-values-from-alfresco-global-properties-in-freemarker-and-yui-javas