Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Daniel Aschauer
Variables and methods in web content
October 29, 2012 1:09 AM
Answer

Daniel Aschauer

Rank: Junior Member

Posts: 39

Join Date: October 22, 2012

Recent Posts

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
Pavel Savinov
RE: Variables and methods in web content
October 29, 2012 1:24 AM
Answer

Pavel Savinov

Rank: Junior Member

Posts: 97

Join Date: September 24, 2012

Recent Posts

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:

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

And then use $rate variable.
Daniel Aschauer
RE: Variables and methods in web content
October 29, 2012 2:00 AM
Answer

Daniel Aschauer

Rank: Junior Member

Posts: 39

Join Date: October 22, 2012

Recent Posts

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)..
Gaurav Jain
RE: Variables and methods in web content
October 29, 2012 2:20 AM
Answer

Gaurav Jain

Rank: Regular Member

Posts: 141

Join Date: January 31, 2011

Recent Posts

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
RE: Variables and methods in web content
November 23, 2012 5:15 AM
Answer

Daniel Aschauer

Rank: Junior Member

Posts: 39

Join Date: October 22, 2012

Recent Posts

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
Pavel Savinov
RE: Variables and methods in web content
November 23, 2012 8:46 AM
Answer

Pavel Savinov

Rank: Junior Member

Posts: 97

Join Date: September 24, 2012

Recent Posts

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
RE: Variables and methods in web content
November 26, 2012 3:09 AM
Answer

Daniel Aschauer

Rank: Junior Member

Posts: 39

Join Date: October 22, 2012

Recent Posts

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/