What inbuilt parameters can I access in Sitecore X

2020-04-20 03:46发布

问题:

Is there a list of inbuilt parameters available to Sitecore XSLTs? I've looked around but haven't seen anything that looks like a full list, at least not in comparison to the sort of data a .NET component can access directly. Using XSLT out of the box in Sitecore seems a little limited in respect to the data it can easily access in comparison to .NET presentation components.

I'm specifically interested in being able to access various pieces of information relating to running multiple sites and languages on a single instance installation - the home node, host name, site name etc. In .NET most of this seems to be available either through the Sitecore.Context or through .NET server objects. I need to be able to get hold of both context specific information and settings for other domains/sites in the same solution.

E.g. mysite1.com in en-GB and mysite2.com in da-DK are pointing at the same content just in different languages. Both domains could theoretically support further languages, some of which might be shared (e.g. both sites allowed a fr-FR translation). In this case I need to know which site I'm in currently, which language I'm in and which languages are supported. Similar information will be needed to determine e.g. site specific CSS, content sections etc.

If I need to expose these global and site settings how should I go about it? I can see several possible methods, including:

  • Writing extension functions in C#
  • Creating global settings template/item and using an XSLT to read them and convert them into parameters - the XSLT could be included/imported in other XSLTs as required.

The aim is to keep all code as generic as possible.

Is there a best practice for this? What are the drawbacks of the two methods above?

回答1:

Reflector shows that the following are automatically added:

list.AddParam("id", string.Empty, item.ID.ToString());
list.AddParam("lang", string.Empty, Language.Current.Name);
list.AddParam("sc_lang", string.Empty, Language.Current.Name);
list.AddParam("sc_item", string.Empty, GetNodeIterator(item));


回答2:

The full list of available Sitecore extensions for xsl helper functions is documented in the API reference helpfile, available from the link.

The XSL helper functions are contained in the XslHelper Class

Namespaces ► Sitecore.Xml.Xsl ► XslHelper

The helpfile documentation is for C# (in which the extensions are built), but as the documentation notes:

Helper functions for use with xsl files. The public functions in this class can be called from an xsl file by using the sc prefix (ex. sc:fld(...))



回答3:

Stating personal opinion, I think you should be grabbing the answer you already see right in front of you - forget about XSLT and just do C#. I don't know of many (in fact, any) seasoned Sitecore developers who stick with XSLT for anything but the most basic of renderings. This too, is of course, just my own personal view - but I've seen similar statements from many of the Sitecore bloggers out there.

And to answer your question, the drawback is complexity and development time. In writing your functionality, then writing and maintaining XSL helper libraries.