Change theme based on domain?
Change theme based on domain?
Hi.
We would like to be able to have the following: 2 domains, 2 themes, 1 database.
I know there is the domain add-on, which allows two domains to be associated with one store -- but has anyone done the custom coding required to change the theme based on the domain? This is what is required in order for this to work.
Thanks.
We would like to be able to have the following: 2 domains, 2 themes, 1 database.
I know there is the domain add-on, which allows two domains to be associated with one store -- but has anyone done the custom coding required to change the theme based on the domain? This is what is required in order for this to work.
Thanks.
Re: Change theme based on domain?
Read following discussion, it may provide you some information about this
viewtopic.php?f=42&t=7519
viewtopic.php?f=42&t=7519
Re: Change theme based on domain?
Thanks. That information was related, but didn't get into how to actually do it.
I did a quick search and this part of the code looks promising:
Seems like you could set the theme there based on the current URL. Have you or anyone else ever done this?
The domain add-on product description (http://www.ablecommerce.com/Domain-Add- ... 68C51.aspx) says "With customization, it is possible to create different websites that access the same AbleCommerce database. This would typically be the reason to use a dual license key." So it sounds possible.
I did a quick search and this part of the code looks promising:
Code: Select all
public static void BindCmsTheme(Page page, CatalogableBase catalogObject)
{
string theme = catalogObject.ActiveTheme;
if (!string.IsNullOrEmpty(theme))
{
if (CommerceBuilder.UI.Styles.Theme.Exists(theme))
{
page.Theme = catalogObject.ActiveTheme;
}
else
{
//INVALID THEME SPECIFIED, LOG WARNING
Logger.Warn("Invalid theme '" + theme + "' specified for catalog item " + catalogObject.Name + "; theme not applied.");
}
}
}
The domain add-on product description (http://www.ablecommerce.com/Domain-Add- ... 68C51.aspx) says "With customization, it is possible to create different websites that access the same AbleCommerce database. This would typically be the reason to use a dual license key." So it sounds possible.
Re: Change theme based on domain?
Give it a try, create a file and name it ThemeHelper.cs. Then copy past following contents into it and upload this file to your Website/App_Code folder
Now update YourFirstDomain.xyz text with the actual name of your default domain. Finally specify default theme name in place of FirstTheme and alternative theme name for "SecondTheme".
Now you need to make all your store pages to make use of this method. You need to add ThemeHelper usage statement in Page_PreInit method in all retail pages. For example edit ContactUs.aspx file on root and make its content look like
Code: Select all
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using CommerceBuilder.Common;
using CommerceBuilder.Utility;
/// <summary>
/// Summary description for ThemeHelper
/// </summary>
public class ThemeHelper
{
public static void BindTheme(Page page, string url)
{
string theme = (url.Contains("YourFirstDomain.xyz")) ? "FirstTheme" : "SecondTheme";
if (!string.IsNullOrEmpty(theme))
{
if (CommerceBuilder.UI.Styles.Theme.Exists(theme))
{
page.Theme = theme;
}
else
{
//INVALID THEME SPECIFIED, LOG WARNING
Logger.Warn("Invalid theme '" + theme + "; theme not applied.");
}
}
}
}
Now you need to make all your store pages to make use of this method. You need to add ThemeHelper usage statement in Page_PreInit method in all retail pages. For example edit ContactUs.aspx file on root and make its content look like
Code: Select all
<%@ Page Language="C#" MasterPageFile="~/Layouts/Scriptlet.master" Inherits="CommerceBuilder.Web.UI.AbleCommercePage" Title="Contact Us" %>
<%@ Register Assembly="CommerceBuilder.Web" Namespace="CommerceBuilder.Web.UI.WebControls.WebParts" TagPrefix="cb" %>
<script runat="server">
protected void Page_PreInit(object sender, EventArgs e)
{
ThemeHelper.BindTheme(this, Request.RawUrl);
}
</script>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="PageContent">
<cb:ScriptletPart ID="ContactUs" runat="server" Layout="Left Sidebar" Header="Standard Header" LeftSidebar="Our Departments" Content="Contact Us" Footer="Standard Footer" Title="Contact Us" AllowClose="False" AllowMinimize="false" />
</asp:Content>
Re: Change theme based on domain?
Thanks, Mazhar. I didn't get an email notification so I just saw this now. I will give it a shot.
Re: Change theme based on domain?
This worked!!!! Mazhar, thanks so much for your guidance.
The only modification I made was to use Request.Url.AbsoluteUri instead of Request.RawUrl:
I have only tested out the Contact page that you mentioned, but it seems proof that this is possible.
Thank you!
The only modification I made was to use Request.Url.AbsoluteUri instead of Request.RawUrl:
Code: Select all
<script runat="server">
protected void Page_PreInit(object sender, EventArgs e)
{
ThemeHelper.BindTheme(this, Request.Url.AbsoluteUri);
}
</script>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="PageContent">
<cb:ScriptletPart ID="ContactUs" runat="server" Layout="Left Sidebar" Header="Standard Header" LeftSidebar="Our Departments" Content="Contact Us" Footer="Standard Footer" Title="Contact Us" AllowClose="False" AllowMinimize="false" />
</asp:Content>
Thank you!
-
- Ensign (ENS)
- Posts: 4
- Joined: Wed Nov 10, 2010 4:23 am
Re: Change theme based on domain?
We need to manage themse based on domain name too.
I see you were writing your own C# there....does that mean you had to purchase and modify the AbleCommerce source? Or was this possible by just adding a bit of code to one or two folders?
I see you were writing your own C# there....does that mean you had to purchase and modify the AbleCommerce source? Or was this possible by just adding a bit of code to one or two folders?
- jmestep
- AbleCommerce Angel
- Posts: 8164
- Joined: Sun Feb 29, 2004 8:04 pm
- Location: Dayton, OH
- Contact:
Re: Change theme based on domain?
mazar's themehelper.cs wouldn't need the source code. You just create a file called themehelper.cs in the App_Code folder and pick up the code in your display pages (category.aspx, product.aspx, etc) from that by replacing one line of code:
PageHelper.BindCmsTheme(this, _Product);
PageHelper.BindCmsTheme(this, _Product);
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx