0

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

  • Resources
    • views
      • theme 1
        • Product
          • List.html
          • Detail.html
          • ...
      • theme 2
        • Product
          • List.html
          • Detail.html
          • ...
      • theme 3
        • Product
          • List.html
          • Detail.html
          • ...
    • public
      • theme 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?

  • why not look at Drupal maybe they have a good method you can take ideas from? – tgkprog May 6 '13 at 3:10
1

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.

0

Maybe I am misunderstanding what you mean with theme, but a theme is a style for me. So the structure itself remains the same but the visual style can change. To have an idea what I mean, here a few links to the same site with the same content, just with different styles:

For that goal you don't need different views just different CSS. If you want to change the behaviour of the application though, you would basically need to recreate code (which increases duplication). In case of code change (JS is part of a web application as well), you would need to change the connected code of all themes.

Your shown approach fits best for a multi-behaviour application that offers different forms of interaction with it. For such a goal you will need different JS and different views (as the HTML will be different too).

Since you basically put function and style together in a theme, I recommend you to split it up. Have different style possibilities by CSS changes only (use a lot of css classes in the HTML so that you can change the visual appearance). For the functional changes you should allow an option in the application to choose which function shall be used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.