Jump to content

How to render contents/views in the same container in index?


lalogarcia91

Recommended Posts

Hello, I'm new on this forum and I got to the point of help!

I'm sweating blood here!

 

How can I render or "switch" my contents/views inside the same container in my index.php ? Meaning, every time I click on a link (href) I want it to render inside a container in my index. So if I click another link, the previous render will disappear and the new one will appear.

 

Instead of including or requiring my header on every single page/view. I prefer my "href's" to render always in the same container in index.

 

I've been using ajax with onclicks to kinda emulate it, seems ajax is not crawlable by SEO, plus even if manipulated.. I'll rather find the right way to render my contents on my index.

 

 

Thanks a lot!

 

 

 

Link to comment
Share on other sites

PHP doesn't know anything about “containers”.

 

If you want to render different pages with the same index.php script, you have to implement that yourself. You'll need to pass a page identifier as a URL parameter (URL rewriting can prettify this), and then you need code to choose the right page for the given parameter (this can be implemented with an array or a long if statement, for example).

 

A smarter approach is to use a template engine which supports inheritance (like Twig). Then you can define a base template with a header and/or a footer, and each page can insert its specific content into that template.

Link to comment
Share on other sites

PHP doesn't know anything about “containers”.

 

If you want to render different pages with the same index.php script, you have to implement that yourself. You'll need to pass a page identifier as a URL parameter (URL rewriting can prettify this), and then you need code to choose the right page for the given parameter (this can be implemented with an array or a long if statement, for example).

 

A smarter approach is to use a template engine which supports inheritance (like Twig). Then you can define a base template with a header and/or a footer, and each page can insert its specific content into that template.

Thank, the thing is I've done the whole front end which took weeks! It was all vanilla css, html and js.. I'll rather render views using server side than client side.

Link to comment
Share on other sites

I'm not sure what you're trying to tell me. The process I've described is purely server-side.

thank you! It was understood, I was just saying that I prefer the server side method (meaning the one you just told me) instead of using client side such as ajax. It was understood sir, thanks!

Link to comment
Share on other sites

My question is - do you want to refresh your entire page after each new click or not?  If you don't then I think you have to utilize an ajax call to get the server to produce the output for your proposed container (ie, div tag) and then upon return from that exercise you use JS to place the returned data into the div and make it visible.

 

If you don't mind doing a full refresh, then I don't see your problem.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.