Search code examples
javaliferayfreemarkerliferay-7

Liferay 7 - List all blogs in template FreeMarker


I'm using Liferay 7 GA5, and I need to create a template for Web Content to print all blogs, to insert in site footer.

Researching, the neatest solution is this:

<#if entries?has_content>
    <#list entries as cur_entry>
        ${cur_entry.getUrlTitle()}<br>
    </#list>
</#if>

But the variable entries doesn't exist and FreeMarker returns to me error "The following has evaluated to null or missing..."

How I can get all blogs and print their values (image, title, short description, link..) ?

Thank you


Solution

  • The issue is "Web Content to print all blogs" When using templates they are inserted in context according to the type of your template. As you are using web content the entries variable will not exist.

    The way you can proceed is to manually get your entries using Liferay's services, which are populated (if enabled).

    After enabling the service locator, you will be looking for this service:

    https://docs.liferay.com/portal/7.0/javadocs/portal-kernel/com/liferay/blogs/kernel/service/package-summary.html

    From there you can use the service to get the entries you need, maybe you need the count which is available or some other criteria. As long you know you need to get the entries as a list you freemarker code should be fine.