[xwiki-devs] Global Variable?
Hi, We can do things like this in pages. #set( $myvar = ["123"] ) If I want to make a global variable that share across the entire wiki (XE), where can i set that pls? Thanks Art -- View this message in context: http://n2.nabble.com/Global-Variable--tp789520p789520.html Sent from the XWiki- Dev mailing list archive at Nabble.com.
You may use objects on a page. Create a class as you want, and add an object of that class to some page. Then you use the same object always. On Thu, Aug 28, 2008 at 3:29 PM, Art Yeung <[email protected]> wrote:
Hi,
We can do things like this in pages. #set( $myvar = ["123"] )
If I want to make a global variable that share across the entire wiki (XE), where can i set that pls?
Thanks Art -- View this message in context: http://n2.nabble.com/Global-Variable--tp789520p789520.html Sent from the XWiki- Dev mailing list archive at Nabble.com.
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Tiago Rinck Caveden http://caveden.multiply.com
Thanks Tiago, will try that. Tiago Rinck Caveden wrote:
You may use objects on a page. Create a class as you want, and add an object of that class to some page. Then you use the same object always.
On Thu, Aug 28, 2008 at 3:29 PM, Art Yeung <[email protected]> wrote:
Hi,
We can do things like this in pages. #set( $myvar = ["123"] )
If I want to make a global variable that share across the entire wiki (XE), where can i set that pls?
Thanks Art -- View this message in context: http://n2.nabble.com/Global-Variable--tp789520p789520.html Sent from the XWiki- Dev mailing list archive at Nabble.com.
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Tiago Rinck Caveden http://caveden.multiply.com _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- View this message in context: http://n2.nabble.com/Global-Variable--tp789520p789981.html Sent from the XWiki- Dev mailing list archive at Nabble.com.
Hi, Sorry being a newbie here. Managed to create the class and add the property, myvar. However, how can I set the default value? Also, how can I reference the myvar my other page after adding the object into the page? If I change this default value, am I right of thinking all the references in all pages will change? Its not like pages have an instance of the class so they are different copies. Cheers, Tiago Rinck Caveden wrote:
You may use objects on a page. Create a class as you want, and add an object of that class to some page. Then you use the same object always.
On Thu, Aug 28, 2008 at 3:29 PM, Art Yeung <[email protected]> wrote:
Hi,
We can do things like this in pages. #set( $myvar = ["123"] )
If I want to make a global variable that share across the entire wiki (XE), where can i set that pls?
Thanks Art -- View this message in context: http://n2.nabble.com/Global-Variable--tp789520p789520.html Sent from the XWiki- Dev mailing list archive at Nabble.com.
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Tiago Rinck Caveden http://caveden.multiply.com _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- View this message in context: http://n2.nabble.com/Global-Variable--tp789520p834160.html Sent from the XWiki- Dev mailing list archive at Nabble.com.
Hello! On Tue, Sep 2, 2008 at 5:12 PM, Art Yeung <[email protected]> wrote:
Managed to create the class and add the property, myvar. However, how can I set the default value?
Well, as it's "global", I don't understand what you mean by default value... The value that you set by last will be the value to be used. You may use the Object editor (when you hover "Edit", there are many editors, "Object" is one) to add objects onto a page and set their property values.
Also, how can I reference the myvar my other page after adding the object into the page?
You don't need to add the object to every page that will use it, only to the page that will "contain it", otherwise it's not global. All you need is to reference it, and to do it there are API methods that can help. To display the value, for example, I believe you may do the following: #set($document = $xwiki.getDocument("Space.DocName")) #set($object = $document.getObject("Classname")) $document.display("propertyName", $object, $xwiki) I haven't tested that, I'm not sure it will work. By the way, I'm a newbie too, so there maybe there are easier ways of doing global variables, but I don't know.
If I change this default value, am I right of thinking all the references in all pages will change? Its not like pages have an instance of the class so they are different copies.
If you change the property - don't forget to save the document if you're editing by script, $document.save() - every other page that uses the same property of the same object of the same page will be affected. So, it is a reference, not a copy. I don't know how XWiki would handle concurrent edition... Regards, -- Tiago Rinck Caveden http://caveden.multiply.com
Hello Tiago, Thanks for your reply. I should have said it's a Global Constant, rather then variable. It meant to be a fixed value. Got it worked out in the end, as per your suggestion #set($document = $xwiki.getDocument("Space.DocName")) #set($object = $document.getObject("Classname")) #set($var = $doc.get("propertyName")) then split the string into array. $var.split(",") Thanks again. Art Tiago Rinck Caveden wrote:
Hello!
On Tue, Sep 2, 2008 at 5:12 PM, Art Yeung <[email protected]> wrote:
Managed to create the class and add the property, myvar. However, how can I set the default value?
Well, as it's "global", I don't understand what you mean by default value... The value that you set by last will be the value to be used.
You may use the Object editor (when you hover "Edit", there are many editors, "Object" is one) to add objects onto a page and set their property values.
Also, how can I reference the myvar my other page after adding the object into the page?
You don't need to add the object to every page that will use it, only to the page that will "contain it", otherwise it's not global. All you need is to reference it, and to do it there are API methods that can help. To display the value, for example, I believe you may do the following:
#set($document = $xwiki.getDocument("Space.DocName")) #set($object = $document.getObject("Classname")) $document.display("propertyName", $object, $xwiki)
I haven't tested that, I'm not sure it will work. By the way, I'm a newbie too, so there maybe there are easier ways of doing global variables, but I don't know.
If I change this default value, am I right of thinking all the references in all pages will change? Its not like pages have an instance of the class so they are different copies.
If you change the property - don't forget to save the document if you're editing by script, $document.save() - every other page that uses the same property of the same object of the same page will be affected. So, it is a reference, not a copy. I don't know how XWiki would handle concurrent edition...
Regards, -- Tiago Rinck Caveden http://caveden.multiply.com _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- View this message in context: http://n2.nabble.com/Global-Variable--tp789520p835976.html Sent from the XWiki- Dev mailing list archive at Nabble.com.
participants (2)
-
Art Yeung -
Tiago Rinck Caveden