2

I understand the concepts of \t and \n in most programming languages that have dynamic web content. What I use them for, as do most people, is shifting all the fancy HTML to make it all readable and "pretty" in view source. Currently, I am making a website that uses PHP include ("whateverfile.php") to construct the layout. You can probably tell where this is going.

How can I tab over a whole block of a PHP include so it aligns with the rest of the page's source?

If this question is worded incorrectly or doesn't make sense, English is my native language so I can't use any excuses.

SomeShinyObject
  • 7,581
  • 6
  • 39
  • 59
  • To answer the question in the title: ∅. – Konrad Rudolph Aug 01 '11 at 16:10
  • Don't do this. You're just wasting bandwidth. Only you should care what that HTML looks like, not your web visitors, and if you use the proper tools, as suggested by hugo_leonardo, it is a non-issue. – Brad Aug 01 '11 at 16:13
  • 1
    I know exactly what you mean. I had this concern for a while - but I got over it. –  Aug 01 '11 at 16:13
  • Because I am anal retentive....AHHH. I'll just stick with aligning things on my desk and not opening my view source. – SomeShinyObject Aug 01 '11 at 16:16
  • @kay: HTML is both. And it's especially popular because it's quite easily human-readable. Learn about the roots of it and you'll see. – hakre Aug 01 '11 at 16:20
  • @kay: The OP is concerned about the output, not which developer tools to use. And I have not said that you're not allowed to use any tools you like, which for some people might even include plain good old view source. As you can see, I don't even question your motivation. – hakre Aug 01 '11 at 16:34
  • @Tim Completely unrelated. Caring about pretty HTML code is like the blacksmith caring for the proper placement of the bolts at the underbelly of the horse cart. Nobody is ever going to see it but his professional pride demands he apply it. It makes no sense but it also does no harm. – Konrad Rudolph Aug 01 '11 at 18:08
  • @Konrad - you aren't a blacksmith, you are a programmer :) I also take quite a bit of pride in my work. I spend lots of time working so things work faster, better or have new features. The blacksmith cares about placement because incorrectness might result in something bad. [X]HTML can either be parsed without errors, or it can't be parsed without errors. – Tim Post Aug 01 '11 at 19:16
  • @Tim Another example then. In the making of the film Lord of the Rings, they put an intricate ornamental emblem on the inside of King Théoden’s breastplate. This was never shown in the film, nor was it ever intended to be shown. The artists put it there simply because a *real* breastplate would conceivably have one, too. Of course this is stupid and a waste of company time. But the artists took pride in their work. The same is true for HTML code that I produce. (Though to be honest, I don’t do this, but I absolutely understand the desire to do so.) – Konrad Rudolph Aug 01 '11 at 19:30
  • @Konrad I completely understand the motivation. I think perhaps we can agree that we have differing views? If it weren't for convenient update mechanisms, we'd _all_ be arrested for breaking into homes to install new software. I just think that this particular finishing is rather pointless, we disagree and there's arguable merit to each side of the point, which we've stated. – Tim Post Aug 01 '11 at 19:42
  • @Tim I don't understand why you wouldn't want your code presentable and neat? If I was writing a book, it would be formatted, properly punctuated, and my chapters would be in the correct order. If I was painting a picture, I would frame it once complete. I am writing a program, I want it to look good. Plus your comment was unnecessary to the question, as this is a Q&A site, not a forum. Please in the future, if you're two cents is not a correct answer, leave it in your change jar. – SomeShinyObject Aug 04 '11 at 15:16

2 Answers2

3

I think you can do it adding extra tabs in the included .php pages. But i wouldn't recommend that (obviously). Instead, use tools like firebug or chrome's inspect element to look at the code.

Hugo Mota
  • 11,200
  • 9
  • 42
  • 60
3

You can do this by using a layer in your application that is taking care of the output, like a theme system. This will add the additional benefit to you that your code will be better separated into data-processing and output-processing.

A good example is given in the following article: When Flat PHP meets Symfony.

Next to that, there is another trick you can do: Install an output buffer and then run tidy on it to make it look just great: Tidying up your HTML with PHP 5.

On top of this you can always put tabs into your include's output, however you don't know always how much tabs this will need. There are some other tricks related to output buffering and intending html fragments when they return from includes, however this is very specific and most often of not much use. So the two articles linked above might give you two areas to look into which are of much more use for you in the end.

hakre
  • 193,403
  • 52
  • 435
  • 836