Search code examples
phphtmlintellij-ideaphpstormstructural-search

PhpStorm Structural Search


I have a bunch of li tags in PHP Blade templates that I want to convert to div tags and change the class name. Search/Replace would be an easy solution but it will only change the opening tag, not the closing tag. Regex can be dangerous to search/replace over an entire project. So I found out about Structural Search Replace which sounds exactly what I need but can't understand how it works.

Search Template:

<li class="navi-item">
    $content$
</li>

Replace Template:

<div class="menu-item">
    $content$
</div>

Do the search in my views/ directory where all my .blade.php view files are (changing "File Type" to PHP), but it comes up empty.


Solution

  • (changing "File Type" to PHP), but it comes up empty.

    This must be the issue. You see, despite the .php extension, the .blade.php files are NOT PHP but a special Blade file type and the main underlying templating language (after the actual Blade) is HTML. Sadly using the HTML option on SSR does not seem to work as well in my tests. But it works fine if a file extension is actually .html (and treated as "HTML file'' by the IDE of course)...

    Possible workaround based on the above:

    1. Change the file association at Settings/Preferences | Editor | File Types; just add *.blade.php pattern to HTML File (it will ask to remove from Blade, do it).

    2. Do your searches/make replacements (it should work OK).

    3. When all is done: change the file association back.

    Not ideal by any means (as it requires playing with file associations that is inconvenient to do if you need a quick simple search) but at least it works.


    P.S. Found a similar ticket for Smarty. Funny thing is that it says it works for Blade there... https://youtrack.jetbrains.com/issue/WI-50380