Nov 9, 2021 3:30:26 PM Thomas Dumont avatar

PageIncludeService

Definition

PageIncludeServices are services that allow you to include HTML code in the pages of the site through bookmarks placed in the main template of the portal (page_frameset.html).
These services can introduce content but are rather intended insert technical code in non-accessible locations for portlets or the XPageApp. For example insert dynamically, in the part <head> HTML pages, links to CSS style sheets or to RSS files.

Core's PageIncludeServices

Lutece integrates by default several PageIncludeServices :

Name Description
Links Inserting CSS Style Sheets and Specific Javascripts for Installed Plugins
Metas Insert meta tag values ​​from those defined in the file webmaster.properties
Themes Dynamic management of CSS style sheet paths according to the theme associated with the page
Statistics Insert the HTML code specific to the audience measurement tool

The default services are declared in the file lutece.properties.

Creating a PageIncludeService

Declaration

Plugins can add new PageIncludeServices by declaring them in their XML file as follows:

<!-- Page Includes -->
<page-include-services>
    ...
    <page-include-service>
        <page-include-service-name>My Include Service</page-include-service-name>
        <page-include-service-class>fr.paris.lutece.myplugin.web.MyInclude</page-include-service-class>
    </page-include-service>
    ...
</page-include-services>

Implementation

A PageIncludeService must implement the PageInclude interface.

Here is a very simple example of implementation:

import fr.paris.lutece.portal.service.content.PageData;
import fr.paris.lutece.portal.service.includes.PageInclude;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;

public class MyInclude implements PageInclude
{
    private static final String MARK_MY_INCLUDE = "my_include";

    /**
    * {@inheritDoc}
    */
    @Override
    public void fillTemplate( Map<String, Object> rootModel, PageData data, int nMode, HttpServletRequest request )
    {
        rootModel.put( MARK_MY_INCLUDE, "My include content" );
    }
}