QLColorCode and CakePHP Templates
Mac OSX Hint: If you use the QLColorCode plugin for QuickLook to get fancy highlight when viewing a file, you might want to have the same when viewing CakePHP *.ctp and *.thtml files.
It involves a bit of hacking, but not much.
Edit Info.plist
First you need to tell the Plugin about the custom file-types. For that you need to view the package contents of QLColorCode.qlgenerator file.
It should be in /Library/QuickLook or in your home directory ~/Library/QuickLook.
Open the “Contents” folder and open the Info.plist file. Any decent texteditor will do. Now scroll down to line 270 or so. There you will find the UTTypeConformsTo sections.
I just copied the “css” block (from <dict> to </dict>) and placed it right under it.
- Change the UTTypeDescription to “PHP File”.
- Change the UTTypeIdentifier to “public.php”.
Then theres a dict-subsection with public.filename-extension as key.
If you followed my steps it should contain “css” (if so, replace “css” with “php”).
- Duplicate the <string> part a couple times and add “ctp” and “thtml” to the array.
The complete section should then look like this:
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.source-code</string>
</array>
<key>UTTypeDescription</key>
<string>PHP File</string>
<key>UTTypeIdentifier</key>
<string>public.php</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>php</string>
<string>ctp</string>
<string>thtml</string>
</array>
</dict>
</dict>
Save and close the file. Your QuickLook plugin now recognizes ctp and thtml files. That’s great, but you need to do one more thing to actually get PHP syntax coloring.
Edit colorize.sh
Back in your Finder with the “package contents” navigate into the “Resources” folder and open the contained “colorize.sh”. That’s a shellscript which does a bit of evaluation before it actually calls the highlight program.
Around line 36 you’ll find something like a switch-block. Here it’s called “case”… Anyway. You might recognize the schema here and see that each “case” corresponds to a file extension. This is where we jump in and add our .ctp and .thtml sections.
Note that there is no “break” statement like in PHP. Each case ends with a double semicolon instead.
*.ctp )
lang=php
;;
*.thtml )
lang=php
;;
You can put these somewhere in the middle. As said, watch out for the semicolons. Save and close the file. Since you’ve modified the Info.plist in the first step you might have to let your system know about the changes. Execute the following two commands on your Terminal/shell to refresh the QuickLook service.
qlmanage -r /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f -v /Library/QuickLook/QLColorCode.qlmanager
Make sure it’s pointing to the correct plugin path (at the end of the long command..).
After refreshing QL it should work right away. Go to your “views” folder and try it out.
Enjoy!



Thanks for the hint! Didn’t know QLColorCode till today.