Get Current Page URL using XSL for Content Query Web Part
I frequently write custom XSL templates for Content Query Web Part (CQWP) for Rolling up List Items. I use CopyUtil.aspx for link items to to Display Form Pages which on close or after editing the items takes you back to default list item page instead of where CQWP is located.
You can either fix this by
- opening a item new window (target =”_blank” in your href’s )
<a href=”{$DetailPageLink}” title=”{@LinkToolTip}” target=”_blank”>
2. Using Source attribute in your URL. SharePoint ListForm Pages use this to navigate back to location you arrived .
<xsl:variable name=”DetailPageLink” select=”concat($SafeLinkUrl,’&Source=/myPage/CQWP.aspx’)” />
<a href=”{$DetailPageLink}” title=”{@LinkToolTip}”>
3. The Problem with above approach is, If I am reusing this template at different location(page or Site) I would need to recreate this template to just change the source attribute. Also in case you are moving XSL files between environments it could break.
To fix it you can probably use JavaScript to get your current Page URL. I won’t go over this. I will be using often ignored ddwrt xml namespace. http://msdn.microsoft.com/en-us/library/aa505323.aspx (it is 2003 version article but most of the functions work ) and more http://weblogs.asp.net/soever/archive/2005/01/03/345535.aspx
We will be adding this namespace to your XSL file, you can add it to either Main CQWP xsl or ItemStyle.xsl, incase you add it to Main XSL pass it down to Item Template as parameter. I usually add to Item Style XSL .
- Add NameSpace xmlns:ddwrt=”http://schemas.microsoft.com/WebParts/v2/DataView/runtime” at top
- Add a parameter “PageUrl “ <xsl:param name=”PageUrl” /> right below your namespace definitions
3. Concat this parameter as part in your Display URL as part Source query string parameter
<xsl:variable name=”DetailPageLink” select=”concat($SafeLinkUrl,’&Source=’,$PageUrl)” />
<a href=”{$DetailPageLink}” title=”{@LinkToolTip}”>
Related Posts
Display all Fields + Value
Hi,
Thanks for the solution.I have been searching for the solution for a long time.Thanks a lot.
I have question :
How can we add a “new Announcement link ” to CQWP.
HI,
is there any way to get the “Webpart Title” using the XSLT in Content Query Webpart.
I can get the PageUrl and Webpart Id using parameters
but could not get any of the webpart properties, where I am specifically looking to get the “Web Part Title URL” and “Web part Title”
as i have Links in the webpart Body that will link based on values in these two properties.
please, please let me know if you have anywork around to get the webpart Title URL and WEbpart Title using XSl from any of the xsl files out there in sharepoint[contentquerymain.xsl, Itemstyle.xsl, Header.xsl]..
Thank you.