Forum
Maintaining Code Formatting
Is it possible to maintain code formatting while using Perch? I was careful to indent lines and keep my code clean but after implementing Perch on my site, when I view the source, things are quite a mess. Is this normal? Or is there a way I could maintain the formatting by indenting templates the same way etc?
Can you give an example?
Sure. Maybe it isn't a big deal or anything? Just wanted to check. Here's a small example:
Viewing page source:
Before Perch:
Or the nav:
Before:
It looks like there are spaces where the Perch tags have been removed. We don't remove any of your template when we remove standard tags, so if there's whitespace surrounding them then it'll remain.
You can either bunch your templates up around the Perch tags, or another option is to use template comments, which do swallow surrounding whitespace.
Of course, the reason have your source code neat is that it helps you in debugging and maintenance. It's not for the browser - the browser doesn't care. It's not for someone else viewing source on your site - they're using tools that reformat the code anyway. In this case, the code you're needing to keep neat to be easy to work with is the template code.
So I personally would keep my templates neat and not worry about the whitespace in the HTML, because it's really of no consequence.
Awesome, thanks for the detailed explanation. Appreciated!