пʼятниця, 24 листопада 2017 р.

Passing value to WebPart xsl

Sometimes you need to customize a SharePoint web part's appearance on a page, for example you want special look for ContentByQueryWebPart.To do that you can customize few xsl files (ContentQueryMain.xsl, ItemStyle.xsl). There are a plenty of articles about it over the Internet, so I won't talk about this in details.
But what if you want to use some value from the page in your xsl? Luckily there is a way to pass it using ParameterBindings element.

The code below allows you to pass different types of values to your xsl:
<WpNs0:ContentByQueryWebPart ...
WebPartAttributeName="WebPartAttributeValue" >
  ...
  <ParameterBindings>
    <ParameterBinding Name="StaticValue"
      DefaultValue="240px" />
    <ParameterBinding Name="WebPartAttribute"
      Location="WPProperty(WebPartAttributeName)" />
  </ParameterBindings>
</WpNs0:ContentByQueryWebPart>
To use this in your xsl define variables and use them:
<xsl:param name="StaticValue" />
<xsl:param name="WebPartAttribute" />
...
<h1 class="{$StaticValue}">
  <value-of select="$WebPartAttribute" />
</h1>
You can read more about ParameterBinding element here

Немає коментарів:

Дописати коментар