I'm trying to figure out how to configure a custom xslt template for use with a content query web part, specifically the content type of the list item.
I don't know at all what I've doing and there aren't really great tutorials on XSLT. If you know of one please share it.
I've gone into the ItemStyle.xsl file and created my own template based on the existing out of the box WithDocIcon. I started out simple. I added this near the top:
<xsl:variable name="Foo" select="'Hello world'" />
And then this down in the markup part of the template
<div class="bar"> <xsl:value-of select="$Foo" /> </div>
And this wrapped the Hello world in a div on the page. So that is successful and working.
But now I want my
Foo variable to pull its value from the content type of the list item. I realize the single quotes inside the double quotes are what are telling the template that the select is a string. I thought maybe I could put the column name there, but that doesn't work.
<xsl:variable name="Foo" select="ContentType" />
I looked at this Microsoft documentation and the thing I figured might be what I need is OuterTemplate.GetColumnDataForUnescapedOutput? I tried implementing it like this.
<xsl:variable name="Foo"> <xsl:call-template name="OuterTemplate.GetColumnDataForUnescapedOutput"> <xsl:with-param name="Name" select="'ContentType'" /> </xsl:call-template> </xsl:variable>
And that didn't work. I also tried it without the single quotes and for other columns like Title. Nothing worked.
I then found this MS documentation that mentions:
By default, the XSL style sheet that controls the presentation of the Content By Query Web Part renders the Title, Description, ImageUrl, and LinkUrl columns (if present) of the items that the query returns. The Web Part renders the ImageUrl column and the LinkUrl column as an image and as a hyperlink, respectively. The Content By Query Web Part uses XSL style sheets to render these columns by default.
So I edited the CQWP and updated the following two properties
<property name="CommonViewFields" type="string">ContentType,Text;</property> <property name="DataColumnRenames" type="string">ContentType,Description</property>
This works! My understanding is the CommonViewFields is telling the webpart to get the content type and then assigning its value to the Description variable, but then I don't have my Description anymore! I tried renaming it to my own names and that didn't work either.
So is there a way to get the Title, Description, ImageUrl, and LinkUrl as well as add my own columns?