Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 lalogarcia91

lalogarcia91
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 12 August 2017 - 10:38 PM

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!

 

 

 



#2 Jacques1

Jacques1
  • Gurus
  • Turtles all the way down
  • 4,168 posts

Posted 13 August 2017 - 12:28 AM

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.



#3 lalogarcia91

lalogarcia91
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 13 August 2017 - 01:11 AM

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.



#4 Jacques1

Jacques1
  • Gurus
  • Turtles all the way down
  • 4,168 posts

Posted 13 August 2017 - 01:38 AM

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



#5 lalogarcia91

lalogarcia91
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 13 August 2017 - 02:14 AM

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!



#6 ginerjm

ginerjm
  • Members
  • PipPipPip
  • Handball player
  • 3,808 posts
  • LocationVoorheesville NY

Posted 13 August 2017 - 03:56 PM

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.


Edited by ginerjm, 13 August 2017 - 03:58 PM.

JG
PS - If you're posting here you should be using:
        error_reporting(E_ALL);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users