Subscribe Now!

Enter your email address:

Thursday, March 29, 2012

Reading tempelates in liferay




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"
});

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...