1

Is there any way to make PHPStorm apply syntax highlighting to PHP code inside a tag in an XML file?

I'm working on an OpenCart project and I'm using Vqmod, which requires that I write PHP code in an XML file. For example:

<operation>
    <search position="replace"><![CDATA[
        <?php echo "123"; ?>
    ]]></search>

    <add><![CDATA[
        <?php echo "xyz"; ?>
    ]]></add>

</operation>

1 Answer 1

9

1) Settings | File Types -- assign *.xml (or whatever file name pattern you think is more appropriate) to PHP files entry (you may need to remove it from "XML files" first).

This will tell PhpStorm to treat such files as PHP (it's the only way to have PHP support).

The possible negative side -- it's an IDE-wide setting and will affect ALL such files in ALL projects. Therefore -- if you can name such files in some unique way (e.g. double extension: *.php.xml or *.xml.php; unique extension: *.pxml; unique file name ending: *layout.xml) then do it.

2) Settings | Template Data Languages -- find such files (or whole folder) and assign XML in 2nd column.

This will tell PhpStorm to treat such files as "PHP with XML" instead of default "PHP with HTML".


Official manual: http://confluence.jetbrains.com/display/PhpStorm/Syntax+highlighting+of+PHP+inside+JavaScript+%28and+other+languages%29

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for your reply, I am marking it as accepted because it answers my original question. Unfortunatelly, the PHP code is inside CDATA tags and it seems PHPStorm doesn't want to apply syntax highlighting inside those. Any idea for that?
Yes, I reset the settings and now it shows up for me as well. Must be something in the way I configured the editor. I'll try to find out what it is. Thanks for your help.
@LazyOne Do you know if it is possible for step 2 to use file extension rather than file path ?
@syl.fabre Not possible -- Settings screen allows to set it up based on path only (Unless you will code some plugin that would somehow do such job for you dynamically). You can file Feature Request to the Issue Tracker though -- maybe they will implement this one day...
@AndyCorman Settings is for Windows/Linux. On Mac it uses standard Preferences name which is located at the same place where any other Mac program has it. Then, in current versions of IDE -- Preferences | Editor | File Types and Preferences | Languages & Frameworks | Template Data Languages P.S. Settings/Preferences screen has quick search facility -- if you would use it you would find those settings very quickly.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.