-22

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.

19
  • 8
    So...what would make that question even remotely on topic in the first place?
    – Makoto
    Commented Apr 17, 2019 at 21:24
  • 1
    The only ones who can delete answers are users with 20K, or moderators. What, "liberties" are being taken?
    – fbueckert
    Commented Apr 17, 2019 at 21:25
  • @fbueckert: The OP's answer along with a few others were deleted.
    – Makoto
    Commented Apr 17, 2019 at 21:26
  • Idk it threw me off a bit im still getting used to how things work here but the question was pretty simple and could use some editing but I understood exactly what he needed and what issue he was running into its a very common issue new developers run into so I provided a solution as well as 3 others and then someone comes downvotes and deletes the post....thats honestly kinda hurtful
    – CoderJoe
    Commented Apr 17, 2019 at 21:27
  • It's also a duplicate: stackoverflow.com/questions/27662098/… (and 3 more linked within the question itself)
    – Kevin B
    Commented Apr 17, 2019 at 21:27
  • @Makoto I get that. But I'm wondering how that qualifies as a liberty. Those privileges are granted because those users are trusted. Doesn't seem like a liberty to me.
    – fbueckert
    Commented Apr 17, 2019 at 21:27
  • 5
    "Pretty simple" and "understood exactly what he needed" and "what issue he was running into" aren't justifications for topicality. What I'm seeing is a question which is too broad which was inviting all sorts of answers. So I ask again - what would make that question even remotely on-topic in the first place?
    – Makoto
    Commented Apr 17, 2019 at 21:28
  • 1
    @fbueckert: There was a flare-up with a new diamond moderator and their choice of deleting an answer. Some saw this as an atypical use of power. I won't indicate if this is the same case circumstance, but it's similar.
    – Makoto
    Commented Apr 17, 2019 at 21:29
  • 1
    Perhaps I dont fully understand what is on-topic so I will look into that but downvotes and deleting answer should not be okay especially when the answers were all valid answers that could have solved the OP problem
    – CoderJoe
    Commented Apr 17, 2019 at 21:30
  • 6
    You submitted a PHP solution. Ok, well, the OP didn't specify php, but, yeah, your solution would work. So would a python solution. or node.js, or any number of languages that could be used as a webserver. that's... quite broad. The OP needed to specify either A: client-side only, or B: which backend they want to work with. Then we could have closed it as a dupe.
    – Kevin B
    Commented Apr 17, 2019 at 21:32
  • Okay the javascript solution was also downvoted and deleted @KevinB Ive seen questions get put on hold but this is the first time ive seen someone delete the answers
    – CoderJoe
    Commented Apr 17, 2019 at 21:34
  • 3
    They also didn't specify JS. They didn't specify anything, that's the problem.
    – Kevin B
    Commented Apr 17, 2019 at 21:37
  • @CoderJoe JavaScript answer was deleted by author (who also added "javascript" tag to question - which may or may not what OP is interested in, OP only specified HTML5). And with significantly broadened question after edit (asking about perf) that answer no longer provided an answer... (Obviously no idea who/why exactly downvoted it) Commented Apr 17, 2019 at 21:38
  • @AlexeiLevenkov I did not know that he had tagged the question with javascript but I know that it Cody gray who deleted my answer
    – CoderJoe
    Commented Apr 17, 2019 at 21:39
  • 2
    @CoderJoe I don't think ability to see edit history is gated on any reputation... Could not you just check stackoverflow.com/posts/55736038/revisions ? Commented Apr 17, 2019 at 21:44

1 Answer 1

11

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...

  • ...how they're building their site in the first place
  • ...if they're using a framework or template engine to begin with
  • ...what they've actually attempted to do or what they're working with

...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

  1. Create a folder called includes in this folder create a new file called nav.php
  2. Now change any page that you will be calling this nav bar to have a .php file extension
  3. Add the html you need to replicate to includes/nav.php
  4. 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.

7
  • I get what your saying but according to another post on meta meta.stackoverflow.com/questions/382775/… technical correctness is not something that mods delete a post for its a downvote not a deletion
    – CoderJoe
    Commented Apr 17, 2019 at 21:36
  • @CoderJoe and that's why I hate that post. Whenever or not it meets our quality standards is what should be evaluated. That thing didn't.
    – Braiam
    Commented Apr 17, 2019 at 21:39
  • 3
    Yes, but then again I see this from the "usefulness" or "harm" angle. I'm not justifying the mod's actions, but I see no cause to disagree with them. Those answers to me read like they don't contribute to a solution since the problem is ill defined.
    – Makoto
    Commented Apr 17, 2019 at 21:40
  • 6
    meh, the question will be deleted along with the answers anyway. why care that it happened sooner? Now we don't have to deal with the possibility of someone upvoting the answers or bountying it to prevent deletion.
    – Kevin B
    Commented Apr 17, 2019 at 21:42
  • 5
    @CoderJoe note that mods have two sides - "generic exception handler without any domain knowledge but god power" and "expert in several technologies with extra power boosts" - it is ok if "expert in several technologies" part of a mod deletes completely incorrect post (there was post about it recently) Commented Apr 17, 2019 at 21:42
  • According to the help center the reasons why a post might be deleted still do not reflect on the actions...im not gonna keep rambling on about it because its honestly not worth it I just didnt agree with how that was handled
    – CoderJoe
    Commented Apr 17, 2019 at 21:47
  • 1
    FWIW it's too broad because the problem they're trying to solve is actually a very large collection of problems presented as a single problem. Solutions to this one problem would actually entail a bunch of solutions to the smaller problems grouped together, and because all of these individual solutions can vary so greatly it leads to it being just too darn broad. All of this to say that there are any number of ways of solving pretty well any problem that could be presented here, but that doesn't in and of itself make those problems too broad. The problem is that it isn't truly one problem.
    – user4639281
    Commented Apr 19, 2019 at 0:52

Not the answer you're looking for? Browse other questions tagged .