AspDot Net Storefront 9.x Add class for each category to the body

88 Views Asked by At

I need to add the name of each category to the body class. I have searched for a way to dump the variable for the category name inside of the template.master file with no luck. I can get the page name or meta info but not the category name.

So it would be <body class="mycategory">

My styling on the whole page (even outside of the entity.category.xml.config) will be affected by this class.

Update: So an example structure on the site would be Clothing > Men > Brand 1 > product 1. I want a a class that shows up for the whole clothing section regardless if I am on a a product, sub category, or sub-sub category.

1

There are 1 best solutions below

11
dubloons On

Start with this in your master file:

<body class='body <aspdnsf:XmlPackage runat="server" PackageName="bodyclass" />'>

Then create an xml package named bodyclass.xml.config. In that file add this:

<xsl:if test="/root/Runtime/EntityName and /root/Runtime/EntityID">
    <xsl:text> e-</xsl:text>
    <xsl:value-of select="/root/Runtime/EntityName" />
    <xsl:text>-</xsl:text>
    <xsl:value-of select="/root/Runtime/EntityID" />
</xsl:if>

This will create classes like e-category-53 rather than category name, but they will give you the same flexibility. They will also work for other entity types like sections and manufacturers.

Another useful one here is:

<xsl:text> url-</xsl:text>
<xsl:value-of select="translate(aspdnsf:StrReplace(/root/Runtime/PageName, '.aspx', ''), '.', '')" />

This will generate a body class based on the url like 'url-c-88-sename'. This will apply to ALL pages, not just entity pages.