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

Jonathan Hell
  • 521
  • 1
  • 5
  • 15
  • You can directly limit the length of your abstracts in your template. – Marco Mercuri Sep 26 '14 at 13:51
  • Thanks for you comment, but the idea here is to add configuration options so the user can do it. Abstract length was an example. – Jonathan Hell Sep 29 '14 at 13:17
  • 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. – Advaita Gosvami Mar 25 '15 at 10:24

4 Answers4

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
Nesrin
  • 395
  • 3
  • 8
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.

Tomas Pinos
  • 2,812
  • 14
  • 22
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]}
andyxmas
  • 521
  • 4
  • 7
-1

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

Ashish Dadhich
  • 4,737
  • 4
  • 17
  • 25