Foros de discusión

Variables and methods in web content

Daniel Aschauer, modificado hace 11 años.

Variables and methods in web content

Junior Member Mensajes: 39 Fecha de incorporación: 22/10/12 Mensajes recientes
Hi!
I recently started evaluation liferay for the use in larger portal project, gone through the documentation, clicked around in the cms and did some portlet development tutorials.
Still I have some principle question on usage of the cms:
In some occasions I would need to include some dynamic content in a created web content, e.g. I need to call a method for currency convertion, get values from the database to include in the content.
Is there a possibility to do this?
Or to I have to write the content and functionality in a template?
Thanks,
Daniel
thumbnail
Pavel Savinov, modificado hace 11 años.

RE: Variables and methods in web content

Junior Member Mensajes: 94 Fecha de incorporación: 24/09/12 Mensajes recientes
Hi Daniel.

You can solve your task in 2 ways:

1) Use AJAX to call some remote service that will give you required info (exchange rates in your case)
2) Use Velocity to call some your local service that will provide the required info, like this:

 #set ($currencyLocalService = $serviceLocator.findService("com.daniel.service.CurrencyLocalService"))
 #set ($rate = $currencyLocalService.getExchangeRate(someDate, currencyAId, CurrencyBId))

And then use $rate variable.
Daniel Aschauer, modificado hace 11 años.

RE: Variables and methods in web content

Junior Member Mensajes: 39 Fecha de incorporación: 22/10/12 Mensajes recientes
Thanks.
Ok, that means this has to go to the template. To make it available to the editor I may use a PLACEHOLDER in the content and then replace it with the calculated value in the template?
I suppose I have access to request / session from the template to use user settings (language, role, and so on)..
thumbnail
Gaurav Jain, modificado hace 11 años.

RE: Variables and methods in web content

Regular Member Mensajes: 145 Fecha de incorporación: 31/01/11 Mensajes recientes
Daniel Aschauer:
Thanks.
Ok, that means this has to go to the template. To make it available to the editor I may use a PLACEHOLDER in the content and then replace it with the calculated value in the template?
I suppose I have access to request / session from the template to use user settings (language, role, and so on)..


Yes, web-content with structure/template is a kind of quite powerful tool in liferay that can be used for static/dynamic content.
However for security reasons request is not accesible as object in template but $request is in form of xmlRequest. [Refert o here]

You can check the liferay documentation on velocity objects here
Daniel Aschauer, modificado hace 11 años.

RE: Variables and methods in web content

Junior Member Mensajes: 39 Fecha de incorporación: 22/10/12 Mensajes recientes
Hi again!
What is the best way to provide a service that is accessible from within the template. Has that to be implemented as ext-plugin? Or can they be implemented in a portlet-plugin?
Didn't find any good documentation on this issue.
Daniel
thumbnail
Pavel Savinov, modificado hace 11 años.

RE: Variables and methods in web content

Junior Member Mensajes: 94 Fecha de incorporación: 24/09/12 Mensajes recientes
Hi Daniel.

It could be an ext-plugin (if you want to EXTend some existing Liferay portlet/service), a hook(if you want to override some functionality of Liferay service) or a plain portlet with service built with Service Builder.
The way depends only on your project's requirements.
Daniel Aschauer, modificado hace 11 años.

RE: Variables and methods in web content

Junior Member Mensajes: 39 Fecha de incorporación: 22/10/12 Mensajes recientes
As far as I understood the service builder is mainly used for generating and providing services related to DAOs.
So I guess if it just want to provide any other service I would build a service with using service builder or ext, as described http://www.devatwork.nl/2010/04/implementing-a-reusable-liferay-service-without-ext-or-service-builder/