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 7 of 7

Thread: Best way to retrieve category and subcategory list?

  1. #1
    omairkha is offline Member
    Join Date
    Aug 2011
    Posts
    89

    Question Best way to retrieve category and subcategory list?

    Hi,

    I am trying to make a custom nav in ASPDNSF 9.1 and I need to dynamically populate a <ul> with the categories and subcategories.

    What is the best way to retrieve this list?

    Thanks,

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

    Default

    Personally I always do this using a dedicated XMLPackage.

    The XML runs a SQL query to retrieve the Categories (or you can use EntityHelper)
    Then you go through the results and render them on screen within an <ul><li> structure.

    Adam

  3. #3
    omairkha is offline Member
    Join Date
    Aug 2011
    Posts
    89

    Question

    Hi Adam-

    I am new to ASP.NET and XML. (I have good experience with Classical ASP).

    Are there any tutorials you can recommend that I can do that would help me learn how to accomplish this?

    Thanks,

  4. #4
    ROBB is offline Senior Member
    Join Date
    Jun 2011
    Location
    United States
    Posts
    107

    Default Categories and Subcategories

    Although it depends on the application, I would generally agree with Adam. A dedicated XML package would work nicely. Actually, it is pretty much already included with the cart Take a look at the rev.categories.xml.config XML package.

    In its original form, this XML package is designed to pull in categories in an unordered list format (<ul><li>...</li></ul). It also pulls in subcategories for the current category being viewed.

    If you take a look at the Entity template inside the XML package file - you will notice the following conditional if block:
    Code:
    <xsl:if test="count(child::Entity)&gt;0 and (EntityID = $CategoryID or descendant::Entity/EntityID = $CategoryID)">
                            <ul class="tame">
                                <xsl:apply-templates select="Entity">
                                    <xsl:with-param name="prefix" select="concat($prefix, '&#160;&#0160;')"/>
                                </xsl:apply-templates>
                            </ul>
                        </xsl:if>
    This block is responsible for performing a recursive call to the Entity template, in order to pull in subcategories. However, the stock XML package has a couple of conditions that limit the subcategories being pulled in, to those that fall under the current category being viewed by the user.

    If we modify the test condition, we can have all of the categories & subcategories (and sub-sub categories) display - regardless of the current entity or page being viewed.

    To do so, replace the existing conditional block, with the following:

    Code:
     <xsl:if test="count(child::Entity)&gt;0">
                            <ul class="tame">
                                <xsl:apply-templates select="Entity">
                                    <xsl:with-param name="prefix" select="concat($prefix, '&#160;&#0160;')"/>
                                </xsl:apply-templates>
                            </ul>
                        </xsl:if>
    In conclusion, you should be able to reuse most of the code in the rev.categories.xml.config file to achieve a dynamic unordered list.

    For more information on XML packages, see this extensive article from the storefront manual: http://manual.aspdotnetstorefront.co...-packages.aspx

    Hope that helps. Please let me know if you have any questions.
    Last edited by ROBB; 09-22-2011 at 04:25 PM.

  5. #5
    omairkha is offline Member
    Join Date
    Aug 2011
    Posts
    89

    Talking

    Hi Robb-

    Thanks a lot for the info! I'll go through it all and see what I can make happen and let you know if I need any help.

    Thank!

  6. #6
    omairkha is offline Member
    Join Date
    Aug 2011
    Posts
    89

    Question

    Hi Robb-

    I was able to get my custom nav running with the suggestions you made

    I was wondering if there is any way to limit the output to only the first level of sub categories instead of all of the sub categories?

    For example currently the output is:

    Code:
    Products
       >> Category 1 
                  >> Sub Cat 1 
                          >> Sub Sub Cat 1
                          >> Sub Sub Cat 2
                  >> Sub Cat 2 
                          >> Sub Sub Cat 1
                          >> Sub Sub Cat 2
       >> Category 2 
                  >> Sub Cat 1 
                          >> Sub Sub Cat 1
                          >> Sub Sub Cat 2
                  >> Sub Cat 2 
                          >> Sub Sub Cat 1
                          >> Sub Sub Cat 2

    Is there a way to get the following:

    Code:
    Products
       >> Category 1 
                  >> Sub Cat 1 
                  >> Sub Cat 2 
       >> Category 2 
                  >> Sub Cat 1 
                  >> Sub Cat 2
    Thanks again for the help!

  7. #7
    chrismartz is offline Senior Member
    Join Date
    Apr 2010
    Posts
    339

    Default

    I believe this answers your question possibly?

    http://forums.aspdotnetstorefront.co...475#post109475