dnenb Posted June 22, 2013 Posted June 22, 2013 I'm setting a game of mine up with multiple layouts now, but it's tedious and difficult to manage. How should it be done? Using a template engine? Quote
dnenb Posted June 22, 2013 Author Posted June 22, 2013 does the user pick or per page? Right now they can choose between two layouts by going to two different folders on my server, but I'd rather have their choice stored in the db for example. Having two folders requires me to have a lot of similar files between the two (altough the two share certain files). Quote
Guest Posted June 22, 2013 Posted June 22, 2013 Depends, if you use the MVC you could just have 2 views, then depending on the choice of the user change a constant which chooses which folder to choose. If that makes sense? Quote
dnenb Posted June 22, 2013 Author Posted June 22, 2013 Depends, if you use the MVC you could just have 2 views, then depending on the choice of the user change a constant which chooses which folder to choose. If that makes sense? I haven't read a lot about MVC yet, but I guess that's one of the options. Do you use it? Quote
Aventro Posted June 22, 2013 Posted June 22, 2013 Try use the template engine Twig http://twig.sensiolabs.org/ It support inheritance (which you technically are looking for to make templating so easy and nice!), automatic escaping (makes protecting against XSS a piece of cake).... Nice syntax, secure, flexible (you can create functions/helpers to use in your templates) and so on. Quote
Guest Posted June 22, 2013 Posted June 22, 2013 Try use the template engine Twig http://twig.sensiolabs.org/ It support inheritance (which you technically are looking for to make templating so easy and nice!), automatic escaping (makes protecting against XSS a piece of cake).... Nice syntax, secure, flexible (you can create functions/helpers to use in your templates) and so on. How would twig help with multiple templates? Didn't think it could? :s I haven't read a lot about MVC yet, but I guess that's one of the options. Do you use it? Yes I do. Quote
Aventro Posted June 22, 2013 Posted June 22, 2013 How would twig help with multiple templates? Didn't think it could? :s Yes I do. Have a variable defining a layout. $layout = 'default'. //render $twig->render($layout . '/index.twig', $data); Now in your templates/ folder you have folders for each "layout" default/ ...index.twig. admin/ ...index.twig. purplepink/ ...index.twig. ... Quote
Guest Posted June 22, 2013 Posted June 22, 2013 Have a variable defining a layout. $layout = 'default'. //render $twig->render($layout . '/index.twig', $data); Now in your templates/ folder you have folders for each "layout" default/ ...index.twig. admin/ ...index.twig. purplepink/ ...index.twig. ... Oh ok, I thought you insinuated twig had a built in method Quote
Alan Posted June 22, 2013 Posted June 22, 2013 While templates are without a doubt a wise move for almost any self-respecting project these days; with or without them, you can produce beautiful layouts with nothing more than CSS. Consider CSS Zen Garden Design List - where every design differs only in its CSS. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.