Editing the View of a List in SharePoint Designer

I ran into a problem earlier this week where I needed to add an image link to a view in SharePoint 2010. After some head scratching and googling, I came across a good walk though on This Blog that shows you how to edit the  list view markup to contain a custom image.

Before you do this, make sure you throw a few test items in your list, it allows you to select the hyperlink in design view.

If you read the blog link posted above, then skip this next step. But before adding the image you’ll need to either write or generate some xsl script. The easiest way to do this is to let SharePoint Designer generate it for you by opening your list in SPD. When you follow the steps below, SPD automatically converts the standard List View into an XSL List View.

Then go into Design view by clicking on the design button in the bottom left hand side of the window:

Now, select the link in design view and click the arrow that appears, then click on hyperlink options:

You’ll get a warning, click Yes. In the Edit Hyperlink window leave everything the same and click OK.

What this will do is generate some XSL markup in the List View. Go ahead and switch back to code view. Now, the markup can be confusing so I’m going to outline what the <xsl> markup is.

The List View does some checks for a blank URL so it doesn’t attempt to output a blank link, instead it will just output nothing. The markup is below.

<xsl:variable name=”url” select=”$thisNode/@*[name()=current()/@Name]” />
<xsl:variable name=”desc” select=”$thisNode/@*[name()=concat(current()/@Name, ‘.desc’)]” />
      <xsl:when test=”$url=””>
        <xsl:if test=”$desc=””>
          <xsl:value-of select=”$desc”/>
        <a href=”{$url}” >
            <xsl:when test=”$desc=””>
                <xsl:value-of select=”$url”/>
             <a href=”{$url}”><xsl:value-of select=”$url” /><xsl:value-of select=”$desc” /></a>
I’ve bolded the area you will need to change. Instead of the <xsl:value-of select=”$url” /><xsl:value-of select=”$desc” />, you will want to add an image like this: <a href=”{$url}”><img alt=”” src=”[IMG URL]” /></a> 
Once you’ve switched your image into your URL, go ahead and switch back to design view, and check out your changes. If the link to your image is good, you’ll see an image in your link column.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: