[xwiki-users] Reusing macro
I'm quite new in XWiki. I've a Velocity macro of some lines (say 10) I need to use in many pages. I'd like to avoid to repeat such lines for every page. Is it possible to store such macro (with or without parameters) and reuse it everyware ? Tks Tullio -- View this message in context: http://xwiki.475771.n2.nabble.com/Reusing-macro-tp7590736.html Sent from the XWiki- Users mailing list archive at Nabble.com.
Yes, you can use include macro for this. See http://extensions.xwiki.org/xwiki/bin/view/Extension/Include+Macro. On Wed, May 28, 2014 at 6:02 PM, tullio0106 <[email protected]> wrote:
I'm quite new in XWiki. I've a Velocity macro of some lines (say 10) I need to use in many pages. I'd like to avoid to repeat such lines for every page. Is it possible to store such macro (with or without parameters) and reuse it everyware ? Tks Tullio
-- View this message in context: http://xwiki.475771.n2.nabble.com/Reusing-macro-tp7590736.html Sent from the XWiki- Users mailing list archive at Nabble.com. _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
Sorry but I didn't undrstand the suggestion. If I include the page I see the page content in my host page and I don't want it. I need only to include only my few lines of code in order to avoid to rewrite them every time. Tks Tullio -- View this message in context: http://xwiki.475771.n2.nabble.com/Reusing-macro-tp7590736p7590754.html Sent from the XWiki- Users mailing list archive at Nabble.com.
You put the Velocity macro in a separate page inside {{velocity output="false"}} ..Your macro here.. {{/velocity}} and then you include this page in all the pages that need to use that macro. Of course, you don't need a page for each Velcity macro. You just need a page where to put Velocity macros that are used all over your code. Hope this helps, Marius On Thu, May 29, 2014 at 12:13 PM, tullio0106 <[email protected]> wrote:
Sorry but I didn't undrstand the suggestion. If I include the page I see the page content in my host page and I don't want it. I need only to include only my few lines of code in order to avoid to rewrite them every time. Tks Tullio
-- View this message in context: http://xwiki.475771.n2.nabble.com/Reusing-macro-tp7590736p7590754.html Sent from the XWiki- Users mailing list archive at Nabble.com. _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
Tks. But when I include such page how can I recall the macro in the host page ? Tks -- View this message in context: http://xwiki.475771.n2.nabble.com/Reusing-macro-tp7590736p7590757.html Sent from the XWiki- Users mailing list archive at Nabble.com.
{{velocity}} macros in a page are not isolated, they behave as you everything was in the same script so all you have to do is include you page at the beginning and then write a new Velocity script which uses what's in the page you included. On Thu, May 29, 2014 at 1:07 PM, tullio0106 <[email protected]> wrote:
Tks. But when I include such page how can I recall the macro in the host page ? Tks
-- View this message in context: http://xwiki.475771.n2.nabble.com/Reusing-macro-tp7590736p7590757.html Sent from the XWiki- Users mailing list archive at Nabble.com. _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
This means there's no way to define a macro someware and use it like a function (with or without parameters) like {{mymacro}} ? Tks -- View this message in context: http://xwiki.475771.n2.nabble.com/Reusing-macro-tp7590736p7590766.html Sent from the XWiki- Users mailing list archive at Nabble.com.
You are mixing several things. What you are talking about in your last mail is a wiki macro and does not have much to do with Velocity (except for the fact that can put Velocity like any other wiki content in wiki macros) and wiki macros are registered for a wiki (or a whole farm) and can then be used in any page of that wiki. But wiki macro are wiki syntax for which parameters are just text, you can't pass complex objects to a wiki macros, something you can do with Velocity macro. In short wiki macro are more configurable display elements which don't require any include where velocity macro are the functions of the Velocity language and require to be included some way. More about wiki macros: http://platform.xwiki.org/xwiki/bin/view/DevGuide/WikiMacroTutorial On Thu, May 29, 2014 at 6:00 PM, tullio0106 <[email protected]> wrote:
This means there's no way to define a macro someware and use it like a function (with or without parameters) like {{mymacro}} ? Tks
-- View this message in context: http://xwiki.475771.n2.nabble.com/Reusing-macro-tp7590736p7590766.html Sent from the XWiki- Users mailing list archive at Nabble.com. _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
I already used wiki macros but they can't by used everywhere (e.g. I can't use them in a title). I simply need to have some variables I can include in my texts (page body, title etc..) in order to be able to change them in a single point (e.g. my product name). I thought to velocity macro because of limitations of wiki macros but any other solution would be acceptable. Tks -- View this message in context: http://xwiki.475771.n2.nabble.com/Reusing-macro-tp7590736p7590782.html Sent from the XWiki- Users mailing list archive at Nabble.com.
In YourSpace.YourMacros you have: {{velocity output="false"}} #macro (doSomething $param1 $param2) ... #end {{/velocity}} In SomeOtherSpace.SomePage you have: {{include reference="YourSpace.YourMacros" /}} {{velocity}} #doSomething("foo" "bar") {{/velocity}} What part of this was not obvious? If you want to call #doSomething in a document title you can add the macro definition to macros.vm inside the templates folder and then restart the server. On Thu, May 29, 2014 at 2:07 PM, tullio0106 <[email protected]> wrote:
Tks. But when I include such page how can I recall the macro in the host page ? Tks
-- View this message in context: http://xwiki.475771.n2.nabble.com/Reusing-macro-tp7590736p7590757.html Sent from the XWiki- Users mailing list archive at Nabble.com. _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
participants (3)
-
Marius Dumitru Florea -
Thomas Mortagne -
tullio0106