Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-76631

Template Context contributors do not work in Web Content templates

    Details

      Description

      Steps to reproduce:

      1. Clone the Liferay Blade Samples project:

       git clone https://github.com/liferay/liferay-blade-samples.git
      

      2. Modify liferay-blade-samples\maven\themes\template-context-contributor\src\main\java\com\liferay\blade\samples\theme\contributor\BladeTemplateContextContributor.java:

      Replace:

      property = {"type=" + TemplateContextContributor.TYPE_THEME},
      

      with:

      property = {"type=" + TemplateContextContributor.TYPE_GLOBAL},
      

      With this, we want to make the injected variable (sample_text) available for non-theme templates (like ADT's, web content templates, etc).

      See https://dev.liferay.com/develop/reference/-/knowledge_base/7-0/template-context-contributor:

      Are you working with templates that aren't themes (e.g., ADTs, DDM templates, etc.)? You can change the context in which your variables are injected by modifying the property attribute in the @Component annotation. If you want your variable available for all templates, change it to
      
      property = {"type=" + TemplateContextContributor.TYPE_GLOBAL}
      

      3. Build the full maven/ project:

      cd liferay-blade-samples/maven
       mvn clean install
      

      4. Get a Liferay DXP bundle and start it.

      5. Add the Blade basic-api artifact to you Liferay bundle:

      cp ~/.m2/repository/blade/basic-api/1.0.0/basic-api-1.0.0.jar $LIFERAY_HOME/osgi/modules/
      

      6. Deploy the generated template context contributor module jar from the target folder:

      cp liferay-blade-samples\maven\themes\template-context-contributor\target\com.liferay.blade.template.context.contributor-1.0.0.jar  $LIFERAY_HOME/deploy/
      

      7. Log in as admin.
      8. Create and asset publisher ADT adt1 in the default Liferay site, and put in it a line something like:

      xx ${sample_text} xx<br>
      

      9. In the Content section of the default Liferay site, Manage Templates, and modify the Basic Web Content template by adding a similar line to it.

      10. Create two additional pages in the site, put an asset publisher on one (and configure it to use the adt1 template), and put a Web Content Display portlet on the other page.

      11. Create a basic web content and publish it, then configure the WCD portlet to show this article.

      Result: The page with the asset publisher works fine and the value of the sample-text variable ("This is some sample text") is visible in the portlet, while the WCD portlet fails to render, with error:

      The following has evaluated to null or missing:
      ==> sample_text in template "20116#20152#BASIC-WEB-CONTENT" at line 1, column 27

      You can see the full stack trace in the Tomcat console.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  1 year, 36 weeks, 2 days ago

                  Packages

                  Version Package
                  7.0.0 DXP FP37
                  7.0.0 DXP SP7
                  7.0.5 CE GA6
                  7.0.X
                  7.1.0 M1
                  7.1.X
                  Master