How to get client-specific color schemes in Symfony2, based on the url that got you to the site
We have a single webinterface in Symfony2 which is used by a number of clients. Each client enters our site by a different URL. For example:
- client A enters from clientA.our-domain.com
- client B enters from clientB.our-domain.com
- client C might even join from clientC.com, i.e. using thei开发者_Go百科r own selected domain instead of a sub-domain of ours
However, regardless of the URL they use, they end up at the same machine: our website.
Right now we use the same CSS for all of them, regardless of which client. We would love it if we could design a stylesheet for each client with client-specific color schemes. I don't want to set up a separate webserver for each client, so I'm looking to select the stylesheet dynamically.
Now, in the HTTP 'Host' header one can see which URL the client used, right. Can this be used, for example in app.php, to set some global variable which defines the client? Twig might read this variable in the main template and decide which stylesheet to use based on it, perhaps?
Also, should we then use css variables? This might be preferable to keeping complete stylesheet 'clones' for each client, if only the colors change.
So to sum up:
- Can the 'host' HTTP header be used in Symfony2 to indicate to Twig which stylesheet to use?
- Should we use CSS variables to identify the colors in the scheme, or is there a better way?
Thanks in advance!
Dieter
Personally, I'd prefer using a special CSS file for each site (containing the styling, that's different for each site, like colors or background images). E.g. site-clientA.our-domain.com.css
.
Then you could use something like this:
<link rel="stylesheet" type="text/css"
href="/path/to/css/site-{{ app.request.host }}.css" />
Or
{% if app.request.host in ['site-clientA.our-domain.com', 'site-clientB.our-domain.com', 'site-clientC.our-domain.com'] %}
<link rel="stylesheet" type="text/css"
href="/path/to/css/site-style1.css" />
{% elseif ... %}
...
{% endif %}
精彩评论