Milople Inc
Milople Inc

Reputation: 399

Adding an extension to the blog post pages on liferay

My problem is i want to add '.html' extension to my every blog post. For example right now i have a blog post url 'http://www.indu.com/blog/-/blogs/creating-a-custom-portlet-in-liferay' and what i want is 'http://www.indu.com/blog/-/blogs/creating-a-custom-portlet-in-liferay.html'

I would be grateful if any one can help?

Upvotes: 2

Views: 249

Answers (1)

Advaita Gosvami
Advaita Gosvami

Reputation: 358

I wonder why would you want this.

Anyways, I think you can change the urlTitle field of BlogsEntry and append .html to the string. May be use a service-wrapper-hook to append .html to the urlTitle whenever a blog is created or updated.

Or you can even use a ModelListener if it exists for BlogsEntry hook to update the blog's urlTitle by using onCreate & onUpdate methods.

Edit

The urlTitle field is present in the BlogsEntry table.

You can access this in java with the following methods:

BlogsEntry blog = BlogsEntryLocalServiceUtil.getBlogsEntry(90989); // retrieves the blog-entry

String blogUrlTitle = blog.getUrlTitle(); 

blog.setUrlTitle(blogUrlTitle + ".html"); // this would set the string

You can have a check for the blogUrlTitle so that you don't have repeated .html appended to the string:

if (!blogUrlTitle.contains(".html")) { // append only if the title does not contain `.html`
    blog.setUrlTitle(blogUrlTitle + ".html");
}

You can refine your code as you like, the above is just a guide-line.

As a side-note, I would always try to reason with the client why they want something, this helps not only to fend-off bad-change-requests but also helps in giving an alternative to the client (which is less taxing on the developers like us ;-) ). In most cases this helps to understand the client's business better & provide better returns.

Upvotes: 3

Related Questions