principlephpMinor
Best practice for lining up PHP syntax in HTML page
Viewed 0 times
practicephpsyntaxliningforpagehtmlbest
Problem
I'm using Codeigniter but this goes for any project in PHP. Let's say I have the following code in my view. I've been struggling, trying to figure out how best to indent and display PHP code within standard HTML code.
So notice how I nested HTML within the PHP code by escaping w/ the PHP syntax. This can get out of hand if you have lines and lines of code. I'm using Komodo and I've enabled "Indentation Guidelines" but even with that, most of my code doesn't line up. So my question is, how best to handle this?
I've actually resorted to keeping the PHP marker `` to the far left and not indenting them. Seems to work so far ...
...
...
session->flashdata('message')) {
...
...
?>
...
...
So notice how I nested HTML within the PHP code by escaping w/ the PHP syntax. This can get out of hand if you have lines and lines of code. I'm using Komodo and I've enabled "Indentation Guidelines" but even with that, most of my code doesn't line up. So my question is, how best to handle this?
I've actually resorted to keeping the PHP marker `` to the far left and not indenting them. Seems to work so far ...
Solution
You can use other kind of syntax:
So, `` can be in 1 line and I think it's beauty:)
Anyway, There are no any 'right' way to do it. You can(and should) choose your own one
...
...
session->flashdata('message')): ?>
...
...
So, `` can be in 1 line and I think it's beauty:)
Anyway, There are no any 'right' way to do it. You can(and should) choose your own one
Code Snippets
...
...
<div id="subcontent">
<?php if ($this->session->flashdata('message')): ?>
<div class="blah blah">
...
...
</div>
<?php endif; ?>
</div>Context
StackExchange Code Review Q#3498, answer score: 5
Revisions (0)
No revisions yet.