Search code examples
phphtmltextmate2

Find closing html tags nested in php using Textmate?


Is there a way to find the closing html tag that is nested inside php conditionals? For example I have this:

<?php
if (condition) { 
    echo '<div id="optional">';
    } 
?>

<div id="content">
    <p>More content here</p>
    <ul>
        <li>one</li>
        <li>two</li>
        <li>three</li>
    </ul>
    <p>Additional content here</p>
</div>

<?php
if (condition) {
    echo '</div>'; 
    } 
?>

If I place my cursor at the end of div#optional and press SHIFT-CMD-B it only finds the code within the if, it does not search for the next unpaired closing tag. Is there a way to have Textmate search for the next unpaired closing tag?

If I code this differently like this:

<?php
if (condition) { ?>
    <div id="optional">
<?php } ?>

<div id="content">
    <p>More content here</p>
    <ul>
        <li>one</li>
        <li>two</li>
        <li>three</li>
    </ul>
    <p>Additional content here</p>
</div>

<?php
if (condition) { ?>
    </div> 
<?php } ?>

and press SHIFT-CMD-B I get the same result. In Dreamweaver CS6 if I place the cursor at the end of div#optional and select Parent Tag, it will find the closing div tag within the embedded php. This only works using the second version of coding however.

I'm transitioning away from DW to TM and mostly it has been very easy, but this is one problem I have yet to solve. Does anyone know a solution to this?


Solution

  • I found the answer though it needs the Emmet plugin. In Emmet: HTML > Match Pair Tag. This works for either coding method shown in my original post. Well done Emmet!