The difference between sc:fld and sc:field

One of my colleagues noticed that in Sitecore 6 there is a difference between the XSLT functions sc:fld (used since Sitecore 4) and sc:field (new in Sitecore 6). Alexey Rusakov explains about this in detail on his blog.

The difference is that sc:fld does not call the RenderField pipeline when executed. The RenderField pipeline can be used to modify the contents of the field when rendered. For example if you wish to have all external links to open in a new window (as in Alexey’s example) you can create your own function and add it to the RenderField pipeline.

<!-- the title attribute of the a tag is not affected by the RenderField pipeline -->
<a href="{sc:path(.)}" title="{sc:fld('NavigationTitle',.)}">
  <sc:text field=”NavigationTitle” />
</a>

<!-- Here the title attribute is affected by the RenderField pipeline -->
<a href="{sc:path(.)}" title="{sc:field('NavigationTitle',.)}">
  <sc:text field=”NavigationTitle” />
</a>

All other XSLT extensions (sc:text, sc:image, sc:date, …) is affected by the RenderField pipeline.

About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in Sitecore 6 and tagged , , , . Bookmark the permalink.

4 Responses to The difference between sc:fld and sc:field

  1. Pingback: Breadcrumb in Sitecore « Brian Pedersen’s Sitecore and .NET Blog

  2. Pingback: Creating fallback values using the RenderField pipeline « Brian Pedersen’s Sitecore and .NET Blog

  3. bhaskar says:

    hi .thanks for sharing it.I want know how to get the current page from browser using xslt?

    http://csharpektroncmssql.blogspot.com

  4. briancaos says:

    This is one of the reasons you should quit XSLT and move into UserControls instead. XSLT is a scripting language intended to convert one type of XML into another. In Sitecore this means converting the Sitecore database XML into XHTML.
    Getting the page object from the request or any fancy stuff is codebehind, which belongs to user controls.
    You should read these articles on how to use UserControls with Sitecore:
    https://briancaos.wordpress.com/2011/01/25/using-usercontrols-instead-of-xslt-in-sitecore-projects/
    https://briancaos.wordpress.com/2011/08/03/creating-a-tree-like-left-menu-in-sitecore-using-usercontrols-and-c/
    https://briancaos.wordpress.com/2010/06/02/working-with-the-system-web-ui-webcontrols-listview-in-sitecore/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s