[opencms-dev] Sharing content in multisite installation

Christian Steinert christian_steinert at web.de
Wed Feb 3 11:35:11 CET 2010

Lammersdorf, Lorenz wrote:
> Hi all,
> does anybody if this is possible?
> I have a multisite installation of OpenCms 7.04. Let's say in /home/site1/news I've a couple of files I want to use in /home/site2 also.
> A template containing
> <cms:contentload collector="allInFolderDateReleasedDesc" param="/home/site1/news/|PressRelease|4">
> Is there any way to access those files without creating siblings?  
Dear Lorenz

you can not directly read files from another site.

There are several possibilities:
* create the files that you want to share somewhere inside of /system/
* there is a section in one of the xml configuration files in the real 
file system which allows to define immutable resources. Maybe this 
works, maybe this does not work. You have to try.
* use the method CmsObject.setSiteRoot you to switch to a different site 
root temporarily and then switch back after reading what you wanted to 
read. You have to be *very* careful with that, because I don't know if 
this also works if you have several concurrent requests for the same 
session. Also, of course you would have to do the switching in a way 
that ensures the switch-back even if exceptions occur:

   //1.remember current site (CmsObject.getSiteRoot())
     //2.switch to other site root (CmsObject.setSiteRoot)
     //3. do something
   } finally {
     //4. switch back to the previously active project 

To make things clean and thread-safe, you might have to syncronize ALL 
this kind of activity against ONE COMMON lock-object to avoid that 
several requests from the same session damage each other's context while 
working concurrently.

Then, this kind of switching-functionality could be wrapped into a 
custom tag and then used inside of your templates

These are the possibilities that comes to my mind.

Best regards

More information about the opencms-dev mailing list