Dreamweaver Syntax Highlight Tip

I use Dreamwweaver CS3 for all of my code editing, and I currently have the pleasure of working with the new Magento Shopcart Software. While adding Shadowbox to the cart, I ran into the small problem of Magento template files that use the rare .phtml file extension. As Dreamweaver by default does not color code the syntax, it makes it difficult to read the php code that makes up the template file.

Here is how I added syntax highlighting to a specific file type that is not listed by default in Dreamweaver.

First, I noted what language the template file is made up of. Even though the file extension is .phtml, I know that the actual language is php.

Second, I opened the document type config file in the Dreamweaver installation folder. This should be found in this general area.

C:\Program Files\Adobe\Dreamweaver CS3\Configuration\DocumentTypes\MMDocumentTypes.xml

I opened the file with Notepad, and hit Control + F, and entered winfileextension=”php as my search query. This jumped me down to where the list of file types that use a specific syntax highlighting. My list appeared as winfileextension=”php,php3,php4,php5″.

All I did was add a comma and phtml to the end of that list:

winfileextension=”php,php3,php4,php5,phtml”

Then I saved the file and restarted Dreamweaver. Now any file with the .phtml file extension receives the same syntax highlighting as a php document.

Before and After

28 Comments
  1. Ekerete Akpan June 20, 200811:28 pm

    Thanks Chad! Perfect timing.

    Just started a new project at work using the Zend framework and while I could get DW to recognize the extension, syntax highlighting wasn’t working.

  2. Chad Von Lind June 25, 20084:33 pm

    Glad to help. You bring up another good trick.

    Allowing DW to recognize and edit a specific file type

    In DW, go to EDIT > PREFERENCES

    At the end of the list of extensions, hit space, and add your new file extension type.

    I added these 3: .htaccess .info .htpasswd

  3. Mortimer June 28, 20083:08 am

    Thx Chad,
    I was alreday hatin dw for not letting me assign syntax schemes to specific filtypes in the prefs dialog! Wave your mouse in the air and say idahooooooo! ;-)
    Mortimer

  4. Chad Von Lind June 28, 200810:58 am

    Haha. Thats actually how I start my mornings at work, every day.

  5. Robert Perrett June 28, 20086:55 pm

    I too have problems with the color syntaxing, I tried everything to get the code color enabled. I followed the instructions, but the file won’t allow me to save. Do I have to do it in administrative mode?

  6. Jeff September 20, 20088:24 pm

    Found the problem.

    I used PTHML instead of PHTML :)

    Works perfectly now!

  7. Adam November 8, 20089:28 pm

    Thanks for the write up, this also lead me to change the colour syntax for the ‘null’ attribute. By default dreamweaver only converts the uppercase value to green (Which is annoying seeing the true & false attributes are not case dependant) For those interested heres how to do it.

    Open up the file:
    C:\Program Files\Adobe\Adobe Dreamweaver CS4\configuration\CodeColoring\PHP.xml

    Note: I had to copy the file to my desktop, edit then paste back because of Vista’s security…

    Anyways… search for ‘NULL’ and you should find this line: NULL
    Directly above it add: null
    Save and reboot :)

  8. David November 13, 20084:39 am

    Just what i was looking for – thank you

  9. Marco Conti December 14, 20081:30 am

    I could kiss you! I opened the silly phtml file and I looked at that sea of black.. I wanted to cry.

    By the way, if you are interested, I have been writing a few articles on how to use Dreamweaver (CS4 by now) to work with dynamic applications like Joomla, Drupal and, I hope, Magento.

    In short, I do a “view source with” in firefox with the web dev toolbar, save as to a working folder in my local site and I relink the CSS and JS files (in CS4 they actually work in Live View). From then on, working on the CSS and even the PHP files is much easier and faster.

    I am still trying to figure out Magento. Not to crazy about the template system. Too many moving parts, to many static blocks for my taste.
    Thank you for the tip. Appreciated.

  10. mishu January 29, 20094:26 am

    Thanks mate, this was driving me nuts!

  11. Tiffany February 5, 200911:42 am

    Thanks for the tip. I am very pleased that I won’t have to hunt that one down on my own. :)

  12. touristguy March 11, 20091:51 pm

    Thanks man, now my dw is much more usable ;)

  13. Agus Lukman Hakim April 7, 200910:02 pm

    Thank you Coleman! It’s very useful for me.

  14. Iris June 3, 20096:06 pm

    Anyone know how to assign for a filename that has two periods in it? Not even sure what to call that.

    Instead of:
    .html
    I have files named:
    .html.erb

    I assume it’s not working because of the period – any clues?

    winfileextension=”html,htm,shtml,shtm,stm,tpl,lasso,xhtml,thtml,erb,html.erb”

  15. Jpaez June 8, 20099:55 am

    Chad, Thank you, nice and very easy, tks again…

  16. Benjamin June 12, 20091:46 am

    Awesome, just what I was looking for! I can finally read .inc files without suffering a complete mental breakdown :-)

  17. Josh L June 24, 20095:21 pm

    Thanks a bunch for this writeup. I have many .html files with PHP in them, which is now properly highlighted.

    Thanks again!

  18. Mike N September 5, 200910:42 pm

    Thank you so much! This was exactly what I was looking for…

    after struggling for a while trying to get something to work in cake’s custom .ctp file extension I realized I needed my php code highlighting back…

    You saved my night, now I won’t be so confused when trying to escape my quotes!

  19. shaun santa cruz November 4, 20099:19 pm

    Using your method Cake Template Pages or .ctp files now have syntax highlighting. Thanks for posting this!

  20. Sandra January 29, 20108:12 am

    Thank you! I was able to get it working with .master pages. It was quite a hassle to edit without syntax highlighting.

  21. Love Wynott March 5, 201012:01 pm

    Dreamweaver has been my personal goto program for years. I truly do not know what I would do without it. There were times when I initially started using the application, and I thought it was way too complicated. Now I fly around it, and it has turned into a great asset in my personal tool box. Anyway thanks for the information.

  22. firas April 5, 201010:16 am

    thanx a bunch, I used this method to go for .less files. give .less css a try guys, it is really awesome… http://lesscss.org/docs.html

  23. Senica May 10, 20104:30 pm

    Perfect! Thank you.

  24. Charles June 6, 20104:25 am

    Thnx a lot Chad.

  25. Brett October 30, 20103:11 pm

    Thanks Chad.

  26. Tony November 22, 201011:51 am

    Chad ROCKS!

  27. Troy December 4, 20105:36 pm

    Well played.

  28. Jose December 3, 20113:14 am

    Thanks! Working great in CS 5.5!

Submit Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

To include your code, use pastebin, and paste the URL in the comment body. Failure to do so may prevent your comment from appearing. Thank you.