Search code examples
liferayfreemarkerliferay-7liferay-7.4

Liferay 7.4: How to create a configurable web content article footer?


I need to create a footer in a Liferay-project, that can be modified from the instance. I've been trying various things in my footer-code and instance, but haven't figured out how to do it.

Any content inside the footer can't be touched and in page edit mode, Liferay says "This area is defined by the theme. You can change the theme settings by clicking more in the Page Design Options panel on the sidebar". I didn't get any help from Page Design Options either. Is there a way to do this?


Solution

  • I found the answer after hours of work and searching and want to share it with everyone here. The working solution was found here, in one of the comments.

    You need to write some code (I use Freemarker/ftl) and then configure the site pages a bit, but here's how it works:

    1. Put a new setting inside liferay-look-and-feel.xml:
    <settings>
        <setting key="footer-article-id" value="" configurable="true" type="text"/>
    </settings>
    

    This will create a new configurable option in page options, allowing you to input the ID of the web content.

    Page settings

    NOTE: <theme> might get underlined red "The content of element type "theme" must match". This still prints everything correctly, but the tags are given in a wrong order. Inside my <theme>, I have <template-extension>, <settings> and <portlet-decorator> in that order, which removes the error.


    1. Assign a variable in init_custom.ftl (cleans up the footer-code):
    <#assign footer_article_id = getterUtil.getString(themeDisplay.getThemeSetting("footer-article-id"))/>
    

    And then add this to the footer-code, to create the spot, where the content is visible:

    <@liferay_journal["journal-article"]
        articleId=footer_article_id
        groupId=page_group.groupId
    />
    

    After this, everything should be ready code-wise.


    1. Create a Web Content for your footer. In the creation screen, there's an ID on the panel on the right. Publish your content and grab the ID.

    ID in content creation


    1. Finally, go to Site Builder --> Pages and click on configuration from the top bar (behind three dots). You should see the input field like in the first picture: That's where you add the ID.

    Save the settings and your web content should now be in the footer.

    Hope this helps!