I am developing an application which will handle many virtual stores and I would
ID: 651561 • Letter: I
Question
I am developing an application which will handle many virtual stores and I would like to have many themes that the user could choose anytime. I would to know what's the main ideia to implement it. I will be developing it using Symfony 2.
I was thinking about implementing own views and assets for each theme
Resourcesviewstheme 1Product
List.html
Detail.html
...
theme 2Product
List.html
Detail.html
...
theme 3Product
List.html
Detail.html
...
publictheme 1 assets
js
css
images
...
theme 2 assets
js
css
images
...
theme 3 assets
js
css
images
...
And in the database each user would have own preferences(theme name, color, etc...).
I am looking for an implementation which will allow me to add any kind of theme. For exemple, one theme, in main page the cart icon will go cart page and another theme, cart icon will pop up a window showing products.
What's the best approach to implement multi theme web application? What I am missing?
Explanation / Answer
I'd second what Jim Martens writes. Unfortunately I can't leave a comment yet due to too few rep points over here.
Let me add this, though:
A few years back, some 10 years, actually, I emulated the CMS project from which joomla was forked from the ground up, with several features of my own like a completely multilingual interface or a hugely simplified code base with less generalization. To simplify the themes backend, I used different CSSs without changing the interface file--the layout, it was in my index.php. I did over time, however, have to add some small-scale functionality to dynamically generate the CSS. The structure remained the same.
If you are using some database for your project, which I assume you do, you could add on a per-page basis a field stating which theme to use for it. Or you could categorize the tree by telling, instead of which theme to use, the page's parent page to inherit that value from there. The base node of a branch of pages must then--as a database entry--have the field with the theme name.
An easily maintainable approach would be to keep a separate layout file per branch of pages and let them inherit the style and the layout from their respective parent node, so in effect you would only replace the content in that files. The layout would be fixed, the style too. Should you, however, need a dynamically adjustable style, that is, without reloading the page, do it with JavaScript.
You could also have a single file with the basic layout, write specific layout generators, and rewrite the paths to GET via .htaccess on an Apache httpd or in the nginx config. But this is obviously more demanding, albeit easily to scale up.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.