[xwiki-devs] Java functions as macro
Hi guys! I'm trying to add my own macros on xwiki but they are functions made in java. for example if I had to edit a xwiki page and added xwiki.myplugin.function("Mikhael") on the preview my function would show the following Text : "Hello Mikhael your plugin is working!". Now what I want to know is how do a turn xwiki.myplugin.function("Mikhael") into for example " $hi("Mikhael") "? Give it a more macro look. I look foward to your answers and thank you for helping out Mikhael -- View this message in context: http://www.nabble.com/Java-functions-as-macro-tp18214356p18214356.html Sent from the XWiki- Dev mailing list archive at Nabble.com.
On Tue, Jul 1, 2008 at 2:52 PM, MikhaelSantos <[email protected]> wrote:
Hi guys!
I'm trying to add my own macros on xwiki but they are functions made in java. for example if I had to edit a xwiki page and added xwiki.myplugin.function("Mikhael") on the preview my function would show the following Text : "Hello Mikhael your plugin is working!". Now what I want to know is how do a turn xwiki.myplugin.function("Mikhael") into for example " $hi("Mikhael") "? Give it a more macro look.
I don't really see the point... If you simply wand to create your own macro calling you plugin method you can do: #macro(myfunction $param1) xwiki.myplugin.function($param1) #end then #myfunction("Mikhael") You can also store the plugin interface in a variage then call the method: #set($myplugin = xwiki.myplugin.function("Mikhael")) $myplugin.function("Mikhael") By the way calling methods from plugin directly using xwiki.myplugin.function() is not recommended (especially if you use the plugin in more than one place in the same document) as any time you call xwiki.myplugin a new plugin API instance is created.
I look foward to your answers and thank you for helping out Mikhael -- View this message in context: http://www.nabble.com/Java-functions-as-macro-tp18214356p18214356.html Sent from the XWiki- Dev mailing list archive at Nabble.com.
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
On Tue, Jul 1, 2008 at 3:11 PM, Thomas Mortagne <[email protected]> wrote:
On Tue, Jul 1, 2008 at 2:52 PM, MikhaelSantos <[email protected]> wrote:
Hi guys!
I'm trying to add my own macros on xwiki but they are functions made in java. for example if I had to edit a xwiki page and added xwiki.myplugin.function("Mikhael") on the preview my function would show the following Text : "Hello Mikhael your plugin is working!". Now what I want to know is how do a turn xwiki.myplugin.function("Mikhael") into for example " $hi("Mikhael") "? Give it a more macro look.
I don't really see the point...
If you simply wand to create your own macro calling you plugin method you can do: #macro(myfunction $param1) xwiki.myplugin.function($param1) #end
then
#myfunction("Mikhael")
You can also store the plugin interface in a variage then call the method: #set($myplugin = xwiki.myplugin.function("Mikhael"))
I mean #set($myplugin = xwiki.myplugin)
$myplugin.function("Mikhael")
By the way calling methods from plugin directly using xwiki.myplugin.function() is not recommended (especially if you use the plugin in more than one place in the same document) as any time you call xwiki.myplugin a new plugin API instance is created.
I look foward to your answers and thank you for helping out Mikhael -- View this message in context: http://www.nabble.com/Java-functions-as-macro-tp18214356p18214356.html Sent from the XWiki- Dev mailing list archive at Nabble.com.
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
-- Thomas Mortagne
Thank you for your help! -- View this message in context: http://www.nabble.com/Java-functions-as-macro-tp18214356p18217835.html Sent from the XWiki- Dev mailing list archive at Nabble.com.
If you add in your page #macro(hi $name) $xwiki.myplugin.function($name) #end then you will be able to use #hi("Michael") Once you are happy with your macro you can add it to a macros.vm page and declare it in velocities.properties (restart needed) Ludovic MikhaelSantos wrote:
Hi guys!
I'm trying to add my own macros on xwiki but they are functions made in java. for example if I had to edit a xwiki page and added xwiki.myplugin.function("Mikhael") on the preview my function would show the following Text : "Hello Mikhael your plugin is working!". Now what I want to know is how do a turn xwiki.myplugin.function("Mikhael") into for example " $hi("Mikhael") "? Give it a more macro look.
I look foward to your answers and thank you for helping out Mikhael
-- Ludovic Dubost Blog: http://blog.ludovic.org/ XWiki: http://www.xwiki.com Skype: ldubost GTalk: ldubost
On Jul 1, 2008, at 4:43 PM, Ludovic Dubost wrote:
If you add in your page
#macro(hi $name) $xwiki.myplugin.function($name) #end
then you will be able to use
#hi("Michael")
Once you are happy with your macro you can add it to a macros.vm page and declare it in velocities.properties (restart needed)
Note: there is no velocity.properties file anymore ;) I need to implement support for global velocity macros in the preferences UI. Right now if you really want to make them global you'll need to either edit META-INF/plexus/components.xml file located in the xwiki-core- velocity jar, override the definition in your plexus.xml file or add them to your skin's macros.vm on the filesystem. But the simplest (although a bit cumbersome) right now is simply to use #includeMacros("macropage") wherever you need to use them. Thanks -Vincent
MikhaelSantos wrote:
Hi guys!
I'm trying to add my own macros on xwiki but they are functions made in java. for example if I had to edit a xwiki page and added xwiki.myplugin.function("Mikhael") on the preview my function would show the following Text : "Hello Mikhael your plugin is working!". Now what I want to know is how do a turn xwiki.myplugin.function("Mikhael") into for example " $hi("Mikhael") "? Give it a more macro look.
I look foward to your answers and thank you for helping out Mikhael
participants (4)
-
Ludovic Dubost -
MikhaelSantos -
Thomas Mortagne -
Vincent Massol