Thursday, September 10, 2009

Reading tempelates in liferay

Hi Friends,
I have seen many new comers to liferay seems to be struggling regarding the email tempelates.
So I thought why not put the whole procedure in a document which can help. For this reason I am
writing this post may be it is quite simple for many but will be quite helpful for the new comers.


Brief Overview:
If we see in existing liferay source code then we can find the email tempelates regarding

create account and forgot password in com/liferay/portlet/admin/dependencies/ and they are read from there.

In 1 case I can tell you from UserLocalServiceImpl and corresponding entry for each tempelate is there in

portal.properties


Enough theory time to do your self:

1.Just create a folder in ext-impl may be u can choose this path
ext-impl\src\com\mytempelate

2.Write a simple tempelate
eg:
Dear [$TO_NAME$],<br /><br />

Hi this is my first tempelate.<br /><br />


Sincerely,<br />
[$FROM_NAME$]

save this as my_first_tmpl.tmpl


3.make an entry in portal-ext.properties

for our example like this :

ext.myfirst.tempelate=ext-impl\src\com\mytempelate\my_first_tmpl.tmpl
This is just a normal key value pair.

4.Now time to read your tempelate

String firstTemeplate = PrefsPropsUtil.getContent(user.getCompanyId(),"ext.myfirst.tempelate");

or

String firstTemeplate = ContentUtil.get("ext-impl\src\com\mytempelate\my_first_tmpl.tmpl");



5. We can easily replace the content :
String firstTemeplate= StringUtil.replace(firstTemeplate, new String[] {"[$TO_NAME$]","[$FROM_NAME$]"

}, new String[] {

"any_name","any_name"
});

Thats it !!!