Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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,',')
share|improve this answer
    
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 Aug 2 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 Aug 2 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. –  Tiago Duarte Aug 2 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 Aug 3 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 –  Tiago Duarte Aug 3 at 10:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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