lalogarcia91 Posted August 12, 2017 Share Posted August 12, 2017 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! Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted August 13, 2017 Share Posted August 13, 2017 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. 1 Quote Link to comment Share on other sites More sharing options...
lalogarcia91 Posted August 13, 2017 Author Share Posted August 13, 2017 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. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted August 13, 2017 Share Posted August 13, 2017 I'm not sure what you're trying to tell me. The process I've described is purely server-side. Quote Link to comment Share on other sites More sharing options...
lalogarcia91 Posted August 13, 2017 Author Share Posted August 13, 2017 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! Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 13, 2017 Share Posted August 13, 2017 (edited) 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 August 13, 2017 by ginerjm Quote Link to comment Share on other sites More sharing options...
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.