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've got a list that makes use of the "Hyperlink or Picture" field. The list is used to hold URLs.

What I really want to do is to display those URLs, not the pretty descriptions for them.

I searched here for a solution and found http://msdn.microsoft.com/en-us/library/ff604024.aspx

Man, that looks like a lotta work to display a URL, when it's right there.

So, I am appealing to the SP community here, hoping and praying that somebody has a painless means of displaying the URL instead of the description. Does anybody got something?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Customization the Rendering of a Field on a List View using XSLT is preferable option here.

Solution

Note: the method described below represents one of the possible ways how it could be accomplished with XSLT, i.e.:

a)SharePoint Designer (SPD) is used for customization

b)XSLT text is embedded using Xsl property in XSLListViewWebPart

In SharePoint Designer (SPD) open view page in Designer Mode. Select list item in List View that have to be customized (Hyperlink field) and then click Customize Item as shown on picture below enter image description here

Switch to Code mode and find generated code for rendering hyperlink field:

<xsl:template name="FieldRef_Hyperlink_URL_body.Link" ddwrt:dvt_mode="body" match="FieldRef[(@Format='Hyperlink') and @Name='Link']" mode="URL_body" ddwrt:ghost="show" xmlns:ddwrt2="urn:frontpage:internal">
  <xsl:param name="thisNode" select="."/>
  <xsl:variable name="url" select="$thisNode/@*[name()=current()/@Name]" />
  <xsl:variable name="desc" select="$thisNode/@*[name()=concat(current()/@Name, '.desc')]" />
  <xsl:choose>
    <xsl:when test="$url=''">
      <xsl:if test="$desc=''">
        <xsl:value-of select="$desc"/>
      </xsl:if>
    </xsl:when>
    <xsl:otherwise>
      <a href="{$url}" >
        <xsl:choose>
          <xsl:when test="$desc=''">
            <xsl:value-of select="$url"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$desc"/>
          </xsl:otherwise>
        </xsl:choose>
      </a>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

Note:

a) In my case match attribute has following value: "FieldRef[(@Format='Hyperlink') and @Name='Link']", where Name corresponds to field internal name

b) By default for Hyperlink field if description value is empty, then url is displayed

So, if you need for force it to display url instead of description replace it with the following template:

<xsl:template name="FieldRef_Hyperlink_URL_body.Link"  match="FieldRef[(@Format='Hyperlink') and @Name='Link']" mode="URL_body" ddwrt:ghost="">
  <xsl:param name="thisNode" select="."/>
  <xsl:variable name="url" select="$thisNode/@*[name()=current()/@Name]" />
  <a href="{$url}" >
    <xsl:value-of select="$url"/>
  </a>
</xsl:template>

Result pageenter image description here

share|improve this answer
    
Thank you, vgrem. I'm accepting this as the solution and plan on making use of it. I bet we can both agree it's far from painless, though. Does Microsoft expect the typical SharePoint user to do this sort of stuff? I should think not. Maybe this is something they'll add in, what, SharePoint 2016? Ugh. –  Alan M Feb 4 '13 at 18:18
    
:-)I totally agree, it's far from painless. But customizing the rendering of field using XSLT is supposed to be the best option here, we only need SharePoint Designer (no-code solution)... –  Vadim Gremyachev Feb 4 '13 at 20:17
1  
@AlanM if you just leave the description blank, it will display the URL. isn't that enough? :) isn't that the most painless way to do it? also you can paste the same URL in both URL and description. But trying to force eliminate the description from URL is quite another matter, I think it is something what a typical SharePoint user wouldn't want to do at all... Honestly I think you're inventing problems from nowhere and then blaming SharePoint for that. no offense. –  Andrey Markeev Feb 13 '13 at 11:06
    
Leaving the descriptions blank would work fabulously, were it for a new list. Unfortunately, this is for an existing list that has a lot of entries in it. Tried editing in Datasheet View, and you can indeed right-click on the field and pick Hyperlink > Edit Hyperlink and get to the split URL / Description menu to strip out the description. That does take a bit of the sting out of it. –  Alan M Feb 15 '13 at 23:06

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.