Product category ID or Name to appear in body tag or master-column-wrapper

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 anos atrás
Hi,

I have a site where the main category pages use a different background image per each category, this is rendered via a unique css class within the body tag which is generated via the url. What I would like is to have the same category class within the body for the product page to render the same bg image as the parent category, I thought using the category ID would help, but have no way of knowing how to do this, or a better suggestion, any help would be much appreciated.

Nik
7 anos atrás
nclamb wrote:
Hi,

I have a site where the main category pages use a different background image per each category, this is rendered via a unique css class within the body tag which is generated via the url. What I would like is to have the same category class within the body for the product page to render the same bg image as the parent category, I thought using the category ID would help, but have no way of knowing how to do this, or a better suggestion, any help would be much appreciated.

Nik


Hi Nik,

As you can see in the _ColumnsTwo view, the categoryId can be taken this way:
//current category ID
    int currentCategoryId = 0;
    if (Url.RequestContext.RouteData.Values["controller"].ToString().Equals("catalog", StringComparison.InvariantCultureIgnoreCase) &&
        Url.RequestContext.RouteData.Values["action"].ToString().Equals("category", StringComparison.InvariantCultureIgnoreCase))
    {
        currentCategoryId = Convert.ToInt32(Url.RequestContext.RouteData.Values["categoryId"].ToString());
    }


I hope this helped !

Regards,
Deni
7 anos atrás
Many thanks for your reply, how would I render the category id within the body?

Cheers
7 anos atrás
Good question.  Did you find an answer?

JohnJ
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.