2

I have some questions about content query web part with sharepoint 2013

I use the content query to filter a list.

This list has a column type link with some http links.

when I display it with the content query I got something like "http://XYZ.xxx, friendly name".

enter image description here

I would like to change that to friendly name only with href to the http column value as a the link.

How can I achive that?

I already had a look into itemstyle template but not easy to deal with, just be able to find the bullet template i'm using but not able to change anything -(

any help could be usefull.

Many thank you!

1 Answer 1

2

There are a couple of options:

  • If it is a links list, you can use the notes field as display name

    Link: "URL [Custom Columns];"

    Title: "Notes;"

    Description: leave empty

    Template: Image on the Left

  • If it is a custom list with a hyperlink field

    Link: Link_Field_Name

    Title/Description: leave empty

    Template: Image on the Left

  • Create your own template

    You can add a new custom template to the list (dropdown) of available templates:

    1. Open Style Library/ItemStyle.xsl
    2. Paste the code below right above the "Default" template (instead of {$SafeLinkUrl}, which takes us to the display form, we will use the url from the field itself)
    3. Setup your webpart to use the new template

The code:

<xsl:template name="MyCustomTemplate" match="Row[@Style='MyCustomTemplate']" 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>
        <xsl:variable name="TheLink">
            <xsl:value-of select="substring-before($DisplayTitle,',')"/>
        </xsl:variable>
        <div class="item link-item">
            <xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>
            <a href="{$TheLink}" 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="substring-after($DisplayTitle,',')"/>
            </a>
            <div class="description">
                <xsl:value-of select="@Description" />
            </div>
        </div>
</xsl:template>

The only relevant part is:

substring-after($DisplayTitle,',')
11
  • thank you for your reply, I will try it, it's a custom list with a hyperlink type field. I would like to keep the bullets at the beginning. The next step will be adding a picture before the link friendly name. and finaly add a second field from the list being queried. step by step... -)
    – Snake
    Commented Aug 2, 2014 at 22:31
  • I tried to add the custom template into the itemstyle go to the webpart properties but the new template is not there. anything the reload except the page containing the webpart?
    – Snake
    Commented Aug 2, 2014 at 23:09
  • a new item in the dropdown list should appear as soon as you add the template, save the file and refresh the page. Commented Aug 2, 2014 at 23:22
  • Hello, I tried the second change you proposed, It's not diplaying the right field anymore, I have to set the field in Title/description with the column name I want. will try again nwith the template.
    – Snake
    Commented Aug 3, 2014 at 7:50
  • try at least to get you template to appear in the list. edit the default itemstyle, save it, and refresh your page. should work Commented Aug 3, 2014 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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