1

I have a Rendering Parameter Template that is assigned to a sublayout(.ascx). Within the markup of that sublayout I reference an XSLT rendering using the sitecore control.

How can I reference the Rendering Parameter Fields from the nested XSLT rendering?

Josh Wheelock
  • 369
  • 4
  • 9
  • 1
    Found out that the standard doesn't seem to work for you. Please can you check: 1.When assigning a Rendering Parameter Template to a Rendering, make sure that template is inherited from the /sitecore/templates/System/Layout/Rendering Parameters/Standard Rendering Parameters template. 2. the parameters that are being passed to your Rendering are case sensitive. i.e. If your field names on the template are “Title” and “Author” then you will have to specify your parameters accordingly. – Shriroop Nov 18 '13 at 23:22
  • @Shriroop - yeah, got all the basics down. Thanks. – Josh Wheelock Nov 19 '13 at 12:49

1 Answers1

3

As Shriroop says, guessing you tried accessing the rendering parameters directly? Sitecore Rendering Parameters - Alex Shyba blog

If you still want to access the parameters and directly using <xsl:param name="paramName"/> in the XSL does not work the try passing the parameters through to the rendering from code. This is untested since I don't have a Sitecore instance in front of me right now.

Your statically bound control should be included in the ascx, you can set them in the Parameters attribute as 'key=value' pairs:

<sc:XslFile runat="server" ID="scRendering" Parameters="param1=abc&param2=xyz" Path="/path/to/rendering.xslt" />

or from code behind in your .cs file:

// statically
scRendering.Parameters = "param1=abc&param2=xyz";

// using parameters from parent control
Sublayout sublayout = Parent as Sublayout;
scRendering.Parameters = sublayout.Parameters;   

You should now have access to the paramaters in your XSL:

<xsl:param name="param1"/>
<xsl:param name="param2"/>

<xsl:value-of select="$param1" />
<xsl:value-of select="$param2" />

Personally I would convert the XLST to an ASPX and you can bind it as a standard ASP.Net control, passing in the parameters (or an object of those parameters) that you need from code-behind. You can still access Sitecore Context and all other Sitecore API features you need from code. Best would be to just add another placeholder in your control and add the rendering through the Sitecore interface (or in __Standard Values for that template) and assign the Parameters Template to the rendering as well - only downside if you have to set the rendering parameters twice, once for each control, but you can continue to use your XSL and you maintain flexibility.

EDIT: Be careful that you don't use spaces in the names of the fields in your Rendering Parameters Template and make sure the names match in the xslt exactly since it is case sensitive.

jammykam
  • 16,940
  • 2
  • 36
  • 71
  • I have tried accessing the fields directly. I'm very familiar with accessing Rendering Parameters directly from a sublayout using a helper, and directly from xslt. But, my project has received some late requirements that would make it logical for me to add the same component to a few of my modules. Though, because I'm retro-fitting with existing content I want to leave the datasource fields and rendering parameters on the parent. – Josh Wheelock Nov 19 '13 at 12:44
  • Ok, understood. Did you try passing the Parameters through, like in the code snippet above? – jammykam Nov 19 '13 at 13:03
  • Yeah. No luck. Haven't given up though. At the moment I have a working solution, and other tasks to complete so I've got to leave it for now. Will come back to it. I'll post an update. If someone doesn't post a solution sooner. I'm thinking your final suggestion might be the best approach. Well, maybe the best for me comes with a small sacrifice for the UX. – Josh Wheelock Nov 19 '13 at 13:41
  • I've just done some testing, and interestingly if you use `scRendering.Parameters = "param1=abc&param2=xyz";` then that works as expected, but `scRendering.Parameters = sublayout.Parameters` does not. Weird. I'll do a little more testing. – jammykam Nov 19 '13 at 15:14
  • Ok , re-tested and it's working as expected for me in Sitecore 6.6, the field name in your rendering template and param name in xsl need to match exactly, they are case sensitive! Make sure you have no spaces in the field names as well. – jammykam Nov 19 '13 at 15:41