Multiple templates with pages stored in database? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Multiple templates with pages stored in database? (/showthread.php?tid=49863) |
Multiple templates with pages stored in database? - El Forum - 03-05-2012 [eluser]Sven Delle[/eluser] Hi, I've been thinking about this for some time now; I seem to have a hard time getting the real benefit of templates in my case (actually all cases, as I seem to have a certain way to go about things). I find it hard to adapt to the page - template thing. Scenario: I have n number of pages stored in a database (let's say n is 2,345 in this case). These pages ALL use the same template, apart from 37 of them - who use a different template. Or just to make things even worse let's imagine that 28 of the pages use one template, 263 use another, 518 use a third an so on ... you get the picture. Now, the problem is; I can't seem to figure out how to go about this without either creating a huge for loop or switch checking for like something like an id to feed the content to the right template ... I'm looking for a clever way to link database content to a certain template. Using the example above: All pages use ONE template, apart from one page who has a form in the middle of all the the text. Now, I could create a view with a form. Check for that pages id, and feed the view. But this would very quickly become way to hard to maintain. I'm thinking of atomizing all data into chunks; a text chunk, a form chunk, a video chunk, another text chunk etc. And then represent a page by an array of chunk id's. And build a page on that data. That way I'm totally flexible in terms of what a page can contain. And I would only need ONE template - which would simply be a view. Now, someone out there MUST have had needs like this. I'm very eager to hear ANY thoughts going in this direction. Anyone? Or am I the odd lunatic ... Multiple templates with pages stored in database? - El Forum - 03-05-2012 [eluser]Matalina[/eluser] Are all your pages called from the same controller method? Multiple templates with pages stored in database? - El Forum - 03-05-2012 [eluser]Sven Delle[/eluser] That would be the best approach, as I wouldn't want to create n number of controllers. I was thinking more in lines of WHERE to STORE information on WHICH template the SPECIFIC page would use to DIFFERENTIATE them all. I think this is more of a data structure design question. Multiple templates with pages stored in database? - El Forum - 03-05-2012 [eluser]Matalina[/eluser] store template name in the database alonside the page content. Code: //Instead of Where $template_tag_from_db was the template name you stored with the page. Multiple templates with pages stored in database? - El Forum - 03-05-2012 [eluser]Sven Delle[/eluser] It's easy to build a site that consists of like 8 pages. No big deal even creating one controller for each page. But I'm like testing the 1 and a million page version of a website (actually thinking Content Management System). Multiple templates with pages stored in database? - El Forum - 03-05-2012 [eluser]Sven Delle[/eluser] Yeah, thought of that. I just see a bit of redundancy. But that could be handled with using an id, and storing templates in a separate table. So this would be fast, optimized and the right way to go about it? Multiple templates with pages stored in database? - El Forum - 03-05-2012 [eluser]Matalina[/eluser] Only other way I think I would do it is to create each different type of content into its own table in the database, more like content nodes in drupal. ... I have a blog here, an image gallery over here, a form on this one. |