Live Wire Blog from Vortx

Coder’s Corner – Extension Data, ADNSF’s Swiss Army Knife

Out of the box, the Extension Data field isn't used for anything, and the Xml packages don't use this field unless you customize it in, so you may be wondering 'what does it do?' The quick answer? Anything you want it to! This tutorial will show you how to use the Extension Data field to add additional information to your product detail pages. To complete this tutorial, you need access to your site's Xml Packages folder, and a basic knowledge of HTML. You can find the Extension Data field in Products and Categories in AspDotNetStorefront. You may have seen the tab in your product screen admin section over to the far right. Next to the field it says: '(User Defined Data)', which is exactly what it is, extra data as defined by you. You can use this extra field to add and display any additional product-specific information. If you'd like to notify your customers when an item will ship, and that shipping time-frame will vary per product, you can enter the text to display in the Extension Data field, and with a minor customization you can add that to the page. This field can be a lifesaver if you have any other extra details about the product you'd like to add and you've already used your spec sheet field. The Extension Data field is a great tool for us as developers. With Extension Data, we can easily add extra data to the page without having to modify the database schema, or source code, so we've been able to modify the product and category display with Extension Data without taking sites off the upgrade path. If you're new to Xml Packages, XSLT, or AspDotNetStorefront customizations, this is a great place to get started.
  1. Log in to the admin section of your site.
  2. Navigate to a product you'd like to add extra information to through the tree menu under Organization > Manage Categories.
  3. Click on the Extension Data tab to the far right.
  4. In the first field: 'Extension Data (User Defined Data)', enter the information you'd like to appear on the product detail page.
Now that we have data to work with, we can add the extension data field to the Xml Package. Navigate to your site's Xml Packages folder, and locate the Xml Package that is used for that product. If you're not sure which one is being used, go back to admin and go to the main screen of that product. Under the first tab, there is a Display Format Xml Package dropdown menu. The Xml Package selected in that menu is the one being used for that product. Find that file name in your XmlPackages folder, and open it in your favorite text editor. After the file is open, search for the text "<xsl:template match="Product">". Xml packages use these 'template' tags to start a new piece of the template. For instance, in an Xml Package using variants, you'll probably find a 'template match="/"', which is the first template used when the page is loaded. In that template tag, you'll probably see a call to another template called '/root/Products/Product', which is the Product display template, and in there you might find another call to another template called '/root/Variants/Variant'. These are all different pieces of the template that contain different code that is used to control the display format of your product detail page. Each of these template pieces has a different structure of data beneath it, so you'll be able to access different parts of the product display. The Extension Data field is located under /root/Products/Product, so we'll want to find that template and add our Extension Data field there. You can add this field anywhere you like. You'll notice a lot of HTML tags like tables and divs, that will help you locate the correct place to display your Extension Data. Treat this document like a standard HTML page. The structure is similar, so if you want your Extension Data underneath your product description, search for 'description' in your document within the Product template. You'll probably find '$pDescription', this is where it's writing out the description content that you enter in admin. You can add a line break beneath that and add your extension data tag. Once you've found the correct location for your Extension Data field, you can easily place the tag by typing out the following: <xsl:value-of select="ExtensionData" disable-output-escaping="yes"> This is using a simple value-of XSLT element. We're displaying the 'value of' the Extension Data field. The second part of the tag: 'disable-output-escaping' is equally important. When set to yes, all of your HTML tags entered in to your Extension Data field will be 'escaped'. This way, if you'd like to add a line break with the HTML tag <br /> directly in the Extension Data field, it will be added to the code of the page instead of actually written out on the page itself. That's it! After you've added your Extension Data field to your Xml Package and saved your file, you should see your text showing up on your product detail page where it was entered. You may need to refresh your browser in order to see the change. What do you use the Extension Data field for on your site?  Share your experience with the community by leaving a comment below.

Tags: , , , ,

3 Responses to “Coder’s Corner – Extension Data, ADNSF’s Swiss Army Knife”

  1. Coder’s Corner - Extension Data Expanded to XML | Vortx Live Wire Blog Says:

    [...] an earlier post, we talked about using the Extension Data field as extra storage space for additional product [...]

  2. John Says:

    This is article is great! However, I found something lacking with it, there should be a complete code snippet of adding the ExtensionData to your XML package. I don’t seemed to understand it a bit.

    thanks

  3. Thomas Says:

    Great tutorial. I would explain how to bring in ExtensionData through the Entity Helper for use when browsing through, say, Categories.

Leave a Reply