In an effort to share more knowledge about how to develop webpages with Flux CMS, we start a this new category called "Snippets", which will contain little code-snippets, tips and tricks about how to get the most of Flux CMS. This is mainly stuff, we use in our daily coding life :) So let's start:
Sometimes you have to reuse the same static content in different places on a webpage. The xhtml plugin, which is mainly used for static content, supports the xinclude standard for including snippets of other XML documents (better said, the libxml2 library supports the xinclude standard, the xhtml plugin just calls this).
Let's say you want to include the <div id="content"> element from another xhtml document, then you just have to add the following line to your xhtml document:
<div id="content">
<xi:include
href="../anothercollection/index.de.xhtml#xmlns(xhtml=http://www.w3.org/1999/xhtml)xpointer(/xhtml:html/xhtml:body/xhtml:div[@id='content']/node())"
parse="xml"/>
</div>
You should not forget to define the xinclude namespace, somewhere in that document:
xmlns:xi="http://www.w3.org/2001/XInclude"
That's it. You now only have to edit the content at one place (in anothercollection/index.de.xhtml).
The xpath in xpointer() can be anything you like, and be aware, that the href attribute has to be relative. You also can include arbitrary xml files this way, they don't have to be xhtml resources.
There are some ideas to make that easier for the enduser, so he/she doesn't have to remember that whole xi:include string, but these are just ideas and no ETA on that.