Inserting HTML into other HTML files
3 answers were given that did answer the OP question and then they received downvotes (all 3), and then just a min ago someone started deleting the answer with no explanation.
Inserting HTML into other HTML files
3 answers were given that did answer the OP question and then they received downvotes (all 3), and then just a min ago someone started deleting the answer with no explanation.
Just because the answers were had a chance of being valid doesn't mean the question was on-topic to begin with.
It would behoove you to recognize that this question - and similar questions like it - are too broad because they are asking for an unbound data set. That is to say, there are any number of ways that could've solved the OP's problem, yet they failed to provide any constraints or define what "solved" looked like.
For context, this is the full question:
I am creating my first full website and am finding that the code is getting quite long and unorganized.
This is mostly due to duplicated code that must appear on every page. For example, my navigation bar code must be put in every page on my website.
Is there a way to put this code in it's own separate file and simply include the nav.html in each page?
Is this common practice? Will I see any noticeable decrease or increase in loading times?
Thanks in advance
Code organization isn't a concrete or solved problem. Templating is, which could've been a better angle for this question
However, there's no indication from the OP...
...because if they had, then we could actually talk about concrete solutions instead of abstract, fuzzy solutions.
Given that your response leveraged PHP...
You can do this by leveraging PHP
- Create a folder called
includes
in this folder create a new file callednav.php
- Now change any page that you will be calling this nav bar to have a
.php
file extension- Add the html you need to replicate to
includes/nav.php
- Now wherever you want to add the html write the following line
<?php include("includes/nav.php"); ?>
For more information you can see the docs here https://www.php.net/manual/en/function.include.php
...you have no way of objectively saying if your solution would or would not work since you don't know if the OP is using PHP from their given question.