1

I´m using opencms 8.5.4. I have a opencms formatter (a jsp file) where I calculate some variables there that I want to use to modify the meta tags description and the title. What´s the best way to do this?

Edit: Just for the record, I didn´t found a way to do this from the formatter. I moved the logic to the template on the moment of the head drawing instead of doing it inside the formatter. Later I used request.setAttribute to store variables if they were reused inside the formatter.

irbian
  • 178
  • 1
  • 7
  • Where are the variables coming from? Are those page properties? Or formatter variables? Is your question how to read those variables o where to put them, i.e. pageContext.setAttribute(), request.setAttribute() – Mathias Conradt Mar 27 '14 at 06:17
  • They are calculated inside the formatter through an api call. Suppose that I have a containerpage test.html with a formatter formatter.jsp. I visit the page test.html?val=1 and I calculate the title of the page based on that val=1 on formatter.jsp. So I want to use that new title as title of the containerpage. – irbian Mar 27 '14 at 08:00
  • Have you tried to put the variable into the pageContext or request attribute within the formatter, i.e. pageContext.setAttribute("title", "Some title") or request.setAttribute("title", "Some title"), and then fetching it from the container page again: request.getAttribute("title") or pageContext.getAttribute("title"). I haven't tried it, but I would assume that the formatter templates get processed before the container template, therefore this might be worth a try, but not 100% sure. – Mathias Conradt Mar 27 '14 at 08:10
  • The problem is that I don´t have a lot of control of the container page. I´m revisiting the code and it looks like the title is read from So if I´m able to modify that property on the formatter and you are right in that the formatter is processed before the container, it could work. – irbian Mar 27 '14 at 08:17
  • You mean, you are not able to change the source code of the container page? If you have, you could of course just replace the tag with your own code snippet, getting it from the request or pageContext attribute. I don't have any other idea. The opencms.title property is fetched from a persistent property, which means that you would need to change the container page property on every page request. And if the variable calculation is dynamic and the container page template used multiple times, this would not work when the page is read concurrently multiple times and where the variable differs. – Mathias Conradt Mar 27 '14 at 08:24
  • Exactly. A priori, I´m not able to modify that code because my work is on the formatter. I´ll do a test , to see if that request.setAttribute is an option. – irbian Mar 27 '14 at 08:49
  • Well, I continue testing this, but it seems that a request.setAttribute("title", "Some title") on the head.jsp don´t work, when is processed the variable is null. – irbian Mar 27 '14 at 09:29
  • For the record, I finally was able to get access to the rest of the template so I moved the logic to the head and pass needed variables through request.setAttribute – irbian Jun 19 '14 at 19:33

1 Answers1

0

Supose you are in the template and you send the parameter with get or post

<Title>
<c:choose>
<c:when test="${not empty param.val}>
${param.val}
</c:when>
<c:otherwise>
<cms:info property="opencms.title" />
</c:otherwise>
</c:choose>
</Title>

also u can use
request.getParameter("val");
do something
You need to load the page, to see the changes, why? because you are in other formatter that is not in the formatter head or template
The property is just for get the title set in the container page, you dont have to change the title of the container page to show it for some random user. also if u want to change de container page title with code use setValue take a look in the API (i just found for 9.0.1)

If you change the property of the container page, this will be changed for all the users!

FAC
  • 51
  • 5