How to add asset publisher configuration options in LifeRay 6.2
Asked Answered
D

4

6

When using an asset publisher, you can change Display Settings in the asset publisher configuration panel. If you select the Abstracts display template, a new option will be available for you (Abstract Length). How can I add an option like that to my Application Display Templates (ADT) ?

Example for the Abstracts template :

enter image description here

Example for my custom template (Abstract Length not available):

enter image description here

Dalmatian answered 1/8, 2014 at 15:16 Comment(3)
You can directly limit the length of your abstracts in your template.Tonguelashing
Thanks for you comment, but the idea here is to add configuration options so the user can do it. Abstract length was an example.Dalmatian
Based on the value of your display template you want an additional configuration option? Then you may try with a JSP hook on configuration.jsp of Asset Publisher, should not be a problem.Bertero
N
1

You can use substring in velocity code written inside ADT built for news asset publisher, check below code to display 100 character only of about us page

#if (!$entries.isEmpty())
<div class="news">
#foreach ($entry in $entries)
    #set($renderer = $entry.getAssetRenderer() )
    #set($className = $renderer.getClassName() )
    #if( $className == "com.liferay.portlet.journal.model.JournalArticle" )
        #set( $journalArticle = $renderer.getArticle() )
        #set( $document = $saxReaderUtil.read($journalArticle.getContent()) )
        #set( $rootElement = $document.getRootElement() )

        #set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[@name='country-portal-image']") )
        #set( $countryPortalImage = $xPathSelector.selectSingleNode($rootElement).getStringValue() )

        #set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[@name='country-portal-title']") )
        #set( $countryPortalTitle = $xPathSelector.selectSingleNode($rootElement).getStringValue() )

        #set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[@name='country-flag-icon']") )
        #set( $countryFlagIcon = $xPathSelector.selectSingleNode($rootElement).getStringValue() )

        #set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[@name='country-portal-about-us']") )
        #set( $countryPortalAboutUs = $xPathSelector.selectSingleNode($rootElement).getStringValue().substring(0,100) )


        #set( $link = $renderer.getURLViewInContext($renderRequest, $renderResponse, '') )
        #set( $viewURL = $assetPublisherHelper.getAssetViewURL($renderRequest, $renderResponse, $entry))

        #set($news-summary =$entry.getSummary($locale))
         #set($date = $dateTool.format("dd/MM/yyyy hh:mm:ss", $dateTool.toDate( "EEE, dd MMM yyyy hh:mm:ss Z" , $entry.getPublishDate())))
        <div class="new">
            <h1 class="title">$entry.getTitle($locale)</h1>
            $date
                 <img src="$countryFlagIcon"/> 
                <img src="$countryPortalImage"/> 
                <h3 class="sub-title">$countryPortalAboutUs</h3>
            <p class="read-more">
                <a href="$viewURL">Read More</a>
            </p>
        </div>
    #end
#end
</div>
#end
Necessity answered 14/4, 2017 at 18:27 Comment(0)
B
0

You can create JSP hook to customize Asset Publisher configuration.

The original configuration is rendered by /html/portlet/asset_publisher/configuration.portal.jsp.

In your hook, you can include the original jsp and then add your own preferences.

Example:

<%-- Include the original Asset Publisher configuration JSP. --%>
<%@include file="/html/portlet/asset_publisher/configuration.portal.jsp"%>

<%-- Read current value from portlet preferences. --%>
<% String abstractLength = portletPreferences.getValue("abstractLength", "100"); %>

<%-- Hidden div with custom input fields. --%>
<div id="customPreferences" style="display: none;">
    <aui:fieldset label="fieldset.abstractLength">
        <aui:input name="abstractLength" label="abstractLength" value="<%= abstractLength %>">
            <aui:validator name="number"/>
            <aui:validator name="min">1</aui:validator>
        </aui:input>
    </aui:fieldset>
</div>

<%-- JS code to place custom preferences at the end of Display Settings tab. --%>
<%-- It uses jQuery, but it's not a requirement. --%>
<script>
    $(document).ready(function () {
        // find div with custom preferences
        var $customPreferences = $("#customPreferences");
        // find the last fieldset on Display Settings tab
        var displaySettingsLastFieldset = $(".nav-tabs:eq(1)").siblings("div:eq(1)").children().filter("fieldset").last();
        // insert custom preferences after the last fieldset on Display Settings tab
        $customPreferences.insertAfter(displaySettingsLastFieldset);
        // show custom preferences
        $customPreferences.show();
    });
</script>

It is a good approach to extend the original JSPs - ie. include the original and then make the customization. This way, there's a good chance of a painless update to next Liferay versions.

For general guidelines on how to implement JSP hooks, see Liferay Developer's Guide.

Bernina answered 3/4, 2015 at 6:54 Comment(0)
F
0

You can get a list of all the available portletPreference values available to the asset publisher ADT using:

<#list portletPreferences?keys as prop >
    <li>
        ${prop}
    </li>
</#list>

So, for your example, you could get the abstract length value set by the user using:

abstractLength: ${portletPreferences.abstractLength[0]}
Filippa answered 19/4, 2016 at 21:19 Comment(0)
H
-1

best way if you creating your own ADT then manage content length in ADT instead of unnecessarily hooking of AP jsp.

Henson answered 26/10, 2015 at 14:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.