Is there a way to differentiate whether a page has been opened directly in its original location or if it has been included/displayed on a different page?
I am looking for a way to display the info a little differently if it is included on another page, and only show everything when opened directly.
I have a Class setup for Customer Sites that I’ve installed as an extension from a local maven repository with a few site pages created, e.g Sites.Site1.WebHome. On the Home page, Main.WebHome, I am including the site pages using {{include reference="Sites.Site1.WebHome"}} so that all sites are easily visible.
The Sites Class has a property to enter Photos which I don’t want to show when included on the Home page, only when viewing the page directly at Sites.Site1.WebHome.
I’d prefer to be able to specify in the ClassSheet to have a different layout depending on where the page is being viewed as I would only need to update it once in the extension to roll the changes out the all sub wikis for customers. E.g. If the opened page is in place at Sites.Site1.WebHome, show every property and its value. But if opened Main.WebHome and being included on that page, Only show the main address properties.
For that, I guess you can check on which page reference you’re. For instance, retrieve the reference on the document and compare it with where you’re at the moment, and then include the wanted page’s content.
There is a significant difference whether a document is embedded with {{include ../}} or with {{display ../}}:
With {{include../}} all variables like doc, cdoc refer to the outer document.
With {{display ../}}, the document to be embedded is displayed in its own context.
If embedding is always done with {{display ../}} the following query works in all documents to be embedded:
{{velocity}}
#set ($isIncluded= ! ( $request.getRequestURL().toString().replaceAll("^http:","https:").equals($doc.getExternalURL($xcontext.getContext().action).toString().replaceAll("^http:","https:"))))
#if ($isIncluded)
CHECK: included
#else
CHECK: not included (direct view)
#end
{{/velocity}}
but if {{include ../}} is used too, you have do a specific query:
Check if the name of the inner file is mentioned in the query, e.g in the following if the file name of embedded file contains “inner”
#set ($isIncluded= ! ( $request.getRequestURL().toString().replaceAll("^http:","https:").equals($doc.getExternalURL($xcontext.getContext().action).toString().replaceAll("^http:","https:"))
and $doc.fullName.contains("inner")))
The queries depend on the difference in request.getRequestURL() and doc.getExternalURL() when {{display ../}} is used. The get-requests The answers are “normalized” to “https”. The queries note whether the outer document is displayed in edit mode (“preview”) or normally (“view”).
That helped heaps, Though It wasn’t exact for me, because we are using short URLs so it was always different. I had to go a little bit cruder and just check if both the request and the doc URL contained the Parent in the path.
#set ($isIncluded = !($request.getRequestURL().toString().contains('/Sites/') and $doc.getExternalURL($xcontext.getContext().action).toString().contains('/Sites/')))