1

I'm using a Web Part to display a list of filtered pdfs on a page. Managed to get the document name to list without a hitch, but can't find a way to add the date the pdf was added to Sharepoint.

For info, to insert the Web Part in the page I hit Insert on the ribbon, then Web Part, then selected Content Rollup and Content Query.

On looking through the Web Part options, I can see under Presentation there is a field called Title. Currently this contains only Title; - is this the place that will add in a new column with the date created information? If so, what do I need to enter?

Any help on my novice user question would be much appreciated.

1

Try to create a custom item style that will show the Title and date as the following

enter image description here

Steps:

  • via SharePoint Designer > Open your Root site.
  • Go to all files > Style library > XSL Style Sheets > ItemStyle.xml
  • Create a copy from ItemStyle.xml to allow rollback then > Edit it as advanced mode.

enter image description here

Add new style with name TitleDate as the following

<xsl:template name="TitleDate" match="Row[@Style='Actions']" mode="itemstyle">
    <xsl:variable name="SafeLinkUrl">
        <xsl:call-template name="OuterTemplate.GetSafeLink">
            <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="DisplayTitle">
        <xsl:call-template name="OuterTemplate.GetTitle">
            <xsl:with-param name="Title" select="@Title"/>
            <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
        </xsl:call-template>
    </xsl:variable>
    <div class="item link-item">
        <xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>
        <a href="{$SafeLinkUrl}" title="{@LinkToolTip}">
          <xsl:if test="$ItemsHaveStreams = 'True'">
            <xsl:attribute name="onclick">
              <xsl:value-of select="@OnClickForWebRendering"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:if test="$ItemsHaveStreams != 'True' and @OpenInNewWindow = 'True'">
            <xsl:attribute name="onclick">
              <xsl:value-of disable-output-escaping="yes" select="$OnClickTargetAttribute"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:value-of select="$DisplayTitle"/>
        </a>
        <div style="color:black">
          <xsl:value-of select="ddwrt:FormatDate(string(@Actiondeliverydate), 2057, 3)" />
        </div>
    </div>
</xsl:template>
  • Save > Check In > Publish as Major Version.
  • After you finish > go to your QCWP > Edit it > and select your custom style from Presentation > Styles > Item Style > select your new item style TitleDate.
  • In title field, Provide Title.
  • In date field, provide the internal name of your date field name.

Note:

In the above example: I used @Actiondeliverydate but when you edit your CQWP web part, you should provide the internal name of 'Action delivery date' field that in this case is Action_x0020_delivery_x0020_date that will be transferred back to Action delivery date

  • Hi Mohammed, I can't see date field according to your instructions above.Can you please verify? – naijacoder Jan 24 '18 at 12:54
0

Open the itemstyle.xsl file in style library.

There you need to add the following line at the top:

xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime

So overall it will look as below:

<xsl:stylesheet version="1.0" exclude-result-prefixes="x d xsl msxsl cmswrt" 
  xmlns:x="http://www.w3.org/2001/XMLSchema" 
  xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" 
  xmlns:cmswrt="http://schemas.microsoft.com/WebParts/v3/Publishing/runtime"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">

After that, in your xsl template , you need to simply add the below line:

<xsl:value-of select="ddwrt:FormatDate(@Created, 2057, 3)"/>

Reference - Custom Date Formats in SharePoint XSL

Customize itemstyle.xsl

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.