Welcome Guest, Not a member yet? Register   Sign In
Multiple templates with pages stored in database?
#1

[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 ...
#2

[eluser]Matalina[/eluser]
Are all your pages called from the same controller method?
#3

[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.
#4

[eluser]Matalina[/eluser]
store template name in the database alonside the page content.

Code:
//Instead of
$this->load->view('page',$data);
//Use
$this->load->view($template_tag_from_db,$data);

Where $template_tag_from_db was the template name you stored with the page.
#5

[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).
#6

[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?
#7

[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.




Theme © iAndrew 2016 - Forum software by © MyBB