Search code examples
jspjstlopencms

OpenCMS 10 open graph metas


I'm trying to print Open Graph meta in main template but I can't get the information about the content shown on the detail page, I'm only able to access the detail container page.

For example, to establish og:image i created a property on theme's .config, but I can't get this information from the "detailed" content:

<meta name="og:image" content="<cms:property name="mytheme.ogImage" file="uri" default="" />">
<meta name="og:image" content="<cms:property name="mytheme.ogImage" file="search" default="" />">
<meta name="og:image" content="<cms:property name="mytheme.ogImage" file="element.uri" default="" />">
<meta name="og:image" content="<cms:property name="mytheme.ogImage" file="search.element.uri" default="" />">
<meta name="og:image" content="<cms:property name="mytheme.ogImage" file="/.content/blogentries/be_00009.xml" default="" />">

The last is the only one which works, but I neither know how to get the path to the content inside main template.

I suppose there is a simpler way to do it but I don't find it.

Thank you in advance.

PS: I'm working with OpenCMS 10.5.4.


Solution

  • Well, after trying lots of things, the only "solution" I came with is retrieving the resource from the database making a connection directly in Java as show in this example.

    With this connection I made a SQL query to find the resource related to the javax.servlet.forward.request_uri of the current page. Once I have the resource (including its file name) I can get its properties with <cms:property name="mytheme.ogImage" file="${filename}" default="" />