So you’ve got a nice Links list with links to all your favorite internal and external sites and you are displaying them in a Data View web part – but you want the links to those other applications/external sites to open in a new page. That’s a fairly reasonable request. This post will take a look at how you can do do this on a per-item basis using SharePoint Designer, a DVWP, an extra column and a little XSL.
THE INGREDIENTS
THE RECIPE
Let’s start this party by getting a few things in place. First, we need to create a new column that will store the Yes/No to decide to open in a new window or not. Create this column using the Yes/No checkbox and add it to your Links list. Update a few items by checking the box if you want the link to appear in a new window, and leave it empty if not. Now that we that out of the way, fire up your old friend SharePoint Designer. I am doing this in 2010 but the idea is the same for WSS/MOSS.
Go ahead and create a new data view web part with your Links list as the data source if you don’t have this setup already. I am assuming you know how to do this. In any case, be sure to use an empty data view. If you need help, leave me a comment below.
If you are setting up this DVWP right now, you can just use the URL column and insert as a multiple item view. If you want some quick and dirty styling, the bulleted list of titles will get the job done. If you change to this styling, you will want to replace the line:
<xsl:value-of select="@URL.desc" />
with:
<a href="{@URL}"> <xsl:value-of select="@URL.desc"/> </a>
in the rowview template. You can hop to this line of code by clicking a Link list item in the Design view window.
Now to tie in our new column. In the code view, you will want to change the dvt_1.rowview template from something like (yours might be a little different):
<xsl:template name="dvt_1.rowview"> <li class="ms-vb"> <a href="{@URL}"> <xsl:value-of select="@URL.desc"/> </a> <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1"> <br /><span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view" /> </xsl:if> </li> </xsl:template>
to:
<xsl:template name="dvt_1.rowview"> <xsl:variable name="OpenLinkTarget"> <xsl:if test="@NewWindow = 'Yes'">_blank</xsl:if> <xsl:if test="@NewWindow = 'No'">_self</xsl:if> <xsl:if test="@NewWindow = ''">_blank</xsl:if> </xsl:variable> <li class="ms-vb"> <a href="{@URL}" target="{$OpenLinkTarget}" alt="{@URL.desc}"><xsl:value-of select="@URL.desc" /></a><br /> <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1"> <br /><span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view" /> </xsl:if> </li> </xsl:template>
So what exactly did this do? Basically we are just setting a variable called OpenLinkTarget to either _blank or _self depending on whether our NewWindow field is checked or not. Then we set the target in the anchor tag with the variable.
1