Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 4 of 4

Thread: Need ideas on how to dynamically insert "headers" or "footers" into product descriptions at runtime

  1. #1
    shark92651 is offline Member
    Join Date
    Jan 2006
    Posts
    81

    Default Need ideas on how to dynamically insert "headers" or "footers" into product descriptions at runtime

    We have several different categories of products that require some disclaimers or different legal text that I would like to display at the bottom of the product description. In order to make it consistent and easily maintained, I would like to place a macro or something in the text that will get replaced at runtime - similar to the way that a topic can reference another topic with this syntax:

    (!Topic Name="MyTopic"!)

    Ideally I would be able to use this syntax exactly and be able to maintain my footers as topics. My first thought was to just create a different XmlPackage for each "category" and just put the language in there, but I really didn't want to create a bunch of clones of my product package. Also, I need the ability to combine multiple footers on some products. Any thoughts on the best way to approach this? I thought maybe an xslt extension and pass the Description text through a function that does the search/replace prior to display, but would like to find a simpler solution.
    Last edited by shark92651; 05-25-2013 at 05:40 PM.

  2. #2
    shark92651 is offline Member
    Join Date
    Jan 2006
    Posts
    81

    Default

    FYI, I experimented with using a different product XMLPackage and this technique does seem to be a good approach, but only if a single footer is required per product. Below is sample inserted in the XmlPackage

    Code:
    <div>
      <xsl:value-of select="$pDescription" disable-output-escaping="yes"/>
    </div>
    <div>
      <xsl:value-of select="aspdnsf:Topic('ProductFooter.HighCap')" disable-output-escaping="yes"/>
    </div>
    
    Last edited by shark92651; 05-25-2013 at 05:37 PM.

  3. #3
    shark92651 is offline Member
    Join Date
    Jan 2006
    Posts
    81

    Post

    Well I didn't exactly get a flood of suggestions on the forum, but I was able to come up with the exact implementation I was thinking about by creating my own XSLT Extension for ASPDNSF. I found this link very helpful: http://support.webopius.com/viewtopic.php?f=2&t=27 Here is the code for all who are interested.

    First, create a class library in Visual Studio. Make sure you build with the correct .NET runtime that matches your version of ASPDNSF or you will get an error. Here is all the code it took to implement parsing of topic references inside a product description:

    Code:
    using System.Collections.Generic;
    using AspDotNetStorefrontCore;
    
    public class RifleGearXSLT : XSLTExtensionBase
    {
      public RifleGearXSLT()
        : this(null, 1, null)
      {
      }
    
      public RifleGearXSLT(Customer cust, int SkinID)
        : base(cust, SkinID)
      {
      }
    
      public RifleGearXSLT(Customer cust, int SkinID, Dictionary<string, EntityHelper> EntityHelpers)
        : base(cust, SkinID)
      {
      }
    
      public string ParseDescription(string desc)
      {
        Parser p = new Parser(ThisCustomer.SkinID, ThisCustomer);
        return p.ReplaceTokens(desc);
      }
    }
    Copy your .dll assembly into the /bin directory on the website. In my example the filename is RifleGearXSLT.dll

    Next you need to define your XSLT extension in your web.config file:

    Code:
    <!-- Add your own custom XSLTExtensionObjects here                                                                                        -->
    <xsltobjects defaultExtension="">
        <extensions>
            <clear />
            <add name="receipt" namespace="urn:receipt" type="ReceiptXsltExtension, app_code"/>
            <add name="mobile" namespace="urn:mobile" type="Vortx.MobileFramework.MobileXSLTExtensionBase, app_code"/>        
            <add name="RifleGear" namespace="urn:RifleGear" type="RifleGearXSLT" />
        </extensions>
    </xsltobjects>
    In your XMLPackage file you need to add your extension in the <PackageTransform><xsl:stylesheet> tag:

    Code:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:RifleGear="urn:RifleGear" xmlns:aspdnsf="urn:aspdnsf" exclude-result-prefixes="aspdnsf RifleGear">
    Finally, modify the code in your package to pass the description parameter through your extension and it will insert topics in place of the tokens:

    Code:
    <div>
         <!--xsl:value-of select="$pDescription" disable-output-escaping="yes"/-->
         <xsl:value-of select="RifleGear:ParseDescription($pDescription)" disable-output-escaping="yes"/>  
    </div>
    Last edited by shark92651; 05-29-2013 at 03:50 PM.

  4. #4
    webopius is offline Senior Member
    Join Date
    Nov 2008
    Location
    London, UK
    Posts
    440

    Default

    Hi

    Glad to hear my support site does get used!
    Get in touch if you need any further help

    Adam