ist it possible to write a macro, that is / creates a section?
My pages consist of multiple excercises. The respective exercise macro surrounds the exercise with a heading and a footer with some annotations, links to hints and solutions.
It would be nice, if every exercise was a section right away.
Beside the functionality, I have already implemented in my exercise macro, I’d like to achieve two more things:
It should be addressable by an url like so Vergleichsfunktion (I tried to implement that by adding an id="" attribute programmatically, but it does not work properly as soon as the exercise name contains spaces or other special characters)
It should be includeable in another page like so {{display page="Eingangsklasse/BPE_3_2" section="Vergleichsfunktion" /}}
With all those elements, I think it’d be easier for you to use a custom XClass with all the appropriate fields and customize its view template heavily, a bit like we do with the blog class: https://www.xwiki.org/xwiki/bin/view/Blog/BlogPostClass
Is there any reason why you’re not using a XClass coupled with the {{display}} macro?
maybe XClass is the way to go … though I’m not sure …
The wiki contains a lot of pages with exercises, organized into 5 spaces.
If these exercises were objects of type ExerciseClass (extends XClass), how and where would they be instantiated? Can they still be instantiated from within the pages, they live in?
Or would there be a central database of exercises then? That could complicate editing exercise pages quite a bit.
Both would be possible. The default and easiest to setup UX is definitely “a central database” where every exercise would be on its own page under a specific parent.
I’m not sure this would complicate editing much since from what I understood a lot of places would just contain display blocks from other pages anyways. At least here you can have all your exercises contained under the same parent and some preconfigured LiveData to help you search through them.
Actually its only a few excerptional booklets, that display exercises from other pages. Most exercises reside on their respective pages only. I’m afraid, the changes to our wiki would be rather huge. As exercises could not be written at the place, they are displayed anymore.
Easiest would be, if the exercise macro could create something like a section, that is addressable with the display macro. Actually why don’t headings inside a macro create sections?
To explain this, let me quickly explain a bit how macros work in XWiki. When the XWiki syntax is parsed, we create an XDOM, similar to the HTML DOM. Initially, after parsing, every top-level (not nested) macro in the page is a single block in this XDOM. Then, we execute the macro transformation (among other transformations) that iteratively executes the macros, replacing them by the result of the macro execution that can include the content of the macro.
The display macro only searches for sections in the original XDOM, it doesn’t execute any macros before searching for the section. Therefore, it can only find sections that are defined outside any macro call.