Adding header/footer in php (beginner level query) [closed] - php

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
How do we write files that are included in a php webpage using includes or requires.
(1)Is there any programming convention for the stuff?
For example: Do you add title in the header/footer file or not? if yes won't there be two titles one from the file included and one of the file that is including the footer/header file. What about bootstrap/js files do I include them in header/footer file or not? Because header/footer contain the usage of bootstrap classes.Won't importing them again and again increase the loading time of pages? (2)So basically do we add head section? if yes how do these values affect the current document?
As I am just beginner I would be glad if you could share some example that has html and php code in the file that gets included. Along with bit of explanation regarding the questions above (1&2). Thank you.

Instead of asking about includes or requires for rendering conventions I would suggest you learn how does a "Render Engine" works. For example Twig (from Symfony), Blade (from Laravel) or Mustache.
Basically, because you should want to distinguish between the different layers in your system. The rendering layer should not contain any other logic but rendering.
The easiest approach here, especially if you're new, is to go with the MVC (Model-View-Controller). And from there you can escalate the structure.
The answer for this question "Adding header or footer in php" is basically Twig or Blade.

Related

Combining one webpage section into other webpage [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have downloaded a several nulled website templates for testing purposes.
I was wondering if I could combine them into one webpage?
For example, take category page layout from one webpage and implement it to other webpage. Is it possible to create webpage using php and html files combined, lets say index.html and contact.php?
Thank You in advance.
YES, you can. But, it's fairly not easy though.
When you are combining two different templates, each have seperate stylesheets and possible Javascript/JQuery scripts, which conflicts between the two.
And you can combine php and html files in same file.
Just use <?php at the beginning of php code and ?> at the end of php code.
Hope this helps. :)
Yes, it's just a matter of copying the section of code from one file and pasting it in the other. Which is why templates are available in the first place. But notice that you can't go copying PHP code and placubgit in a .html file.

Separating PHP and HTML [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I apologize for asking such a beginner question, but i'm unsure on where else I could go to get such help. I'm currently creating a php website using GoggleApp Engine. I've created a very simple form using html in the same file as my PHP. Now, I know this isn't good practice, so I want to break up my html into it's own file. My only question is, how would I re-write this code assuming that my html is in it's own file?
It is perfectly fine to place your PHP code in the same file as your HTML code. However, if you are going to duplicate code, it would be best to have separate files (maybe say a header and footer file).
That way you can use require_once("header.php") and require_once("footer.php") in each file that wants to use the top and bottom portions of your code.
As Sven mentioned, you can look into templating. You can also look into coding habits such as MVC (Model View Controller) and similar methods.

Is-it worth to split a page into many pages? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I've got a question about php and pages :
Is-it worth to split the code into many other files ?
So at the end, the index.php would be composed of :
include 'footer.php';
include 'header.php';
include 'home.php';
include 'load.php';
[...]
Or should I put all the code in an unique page ?
Other question, if I include a php page, could all the vars created in the included page be used in the main page, or should-I use $_SESSION ?
Thank you all for your help !
As for your main question it’s worth. In fact, it will be a pain for you to manage your web page if you don’t follow this method in the long run. I am not a php guy but I can tell you this because this is a universal truth. The idea here is to write once and use anywhere necessary. You don’t want to write the same thing again and again, do you? That’s why we produce function when programming. We define a function and use it as many times we want. Now consider you have suddenly found that you need some modification to do , as you have created a function you can make the change in just one place and it will be reflected everywhere without touching a single line of code outside the function’s code. In actual project change is a constant. That’s why we find many design pattern in the software industry like MVC.
In a web project, mostly (not always) the header, navigation, footer are same across all the pages. Therefore, you should consider making different file for these stuff and you should always put your content in your index.php file which are unique for index page.

How can i display a navigation bar across multiple webpages? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I know CSS and HTML to a reasonable degree, but I've never built a multi-page website before.
I have a header area of my site coded, and want it to display it across multiple webpages. How can I do this?
Save it as header.php/header.html whichever one you need. Then, from every file you code from then on, you can <?php include('header.php');?>. The files you include in HAVE to be .php or it wont work.
Same applies to jsp if for any reason php didnt work or you fancied a change of pace
Create a file called header.jsp then use the tag below when you want to include it on a page.
<jsp:include page="{header.jsp}"/>
This is maybe of no use to you but who knows it may help someone. Some people find this easier and some find this harder it depends on your programming background.
Use a web programming language (PHP / ASP.Net / Whatever you like) to include the navigation bar in all the pages. There are template languages like Twig that can do that for you in a smarter way and provide you with additional template features, if you might need them.

separating header and footers into their own files [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Question: I've read a lot of tutorials/books that have taught putting the header and footers into their own files and using php to include them in the content pages.
However, if you have javascript running in those headers or footers- isn't this "bad" design- or does it not really matter?
I guess I take out the javascript if it's not needed for a page and I don't really mind CTRL+C. However I can see the usefulness and efficiency of making a change in only one file instead of all of them.
You should start using some template engine instead. Something to start with: Twig and Smarty
The most important feature you will like is called Template Inheritance
I would always separate your header and footer files out, it is a nightmare otherwise!
Just load in the JS when you need it, if using PHP just check the $_SERVER vars - http://uk.php.net/manual/en/reserved.variables.server.php

Categories