Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Sublime Text work with Cakephp (ctp) view files

I'm trying to get Sublime Text 3 to work well with Cake's ctp (view) files. The syntax highlighting works fine out-of-the-box, but I can't get the HTML autocomplete to work.

If I open an .html file, I can get the tags and attributes to autocomplete (except in the attribute "style", it doesn't autocomplete CSS styles).

However, if I work on a .ctp file, autocomplete doesn't work at all. I've already tried changing the View->Syntax settings to both PHP and HTML and nothing... I've even tried using the "Open all with current extension as..." with no result.

I've tried using different plugins (ApplySyntax, cakephp plugins, etc) with any success.

Another thing I've noticed, also for javascript code, is that for "short" tags and functions, if I place the cursor at the opening tag or {, the closing tag or } gets automatically highlighted. However, if there's a bunch of lines of code in-between (same language) then the highlight won't happen...

Any help with these things would be really appreciated! I really want to like and use Sublime!

like image 354
Albert Avatar asked Sep 29 '14 23:09

Albert


People also ask

What is CTP CakePHP?

ctp (CakePHP Template). These files contain all the presentational logic needed to get the data it received from the controller in a format that is ready for the audience you're serving to.

What are CTP files?

ctp files are CakePHP Template Pages, that is view templates. It is used for the view in the MVC that shows output in the browser and act as a view for a controller action. JSON, XML, HTML, JS, CSS, PHP code can be written in it. More than as HTML/PHP pages, it shows data sent from controller.


2 Answers

Just install the ApplySyntax plugin for sublime-text.

ApplySyntax can be installed in a variety of ways:

  • Through Package Control http://wbond.net/sublime_packages/package_control

    Open Package Control Select 'Install Package' Find and select 'ApplySyntax'

  • By cloning this repository in Packages

    cd into your Packages folder
    git clone git://github.com/facelessuser/ApplySyntax.git .
    
  • By downloading the files and placing them in a directory under Packages, such as ApplySyntax or User

    If you don't put the files in Packages/User (you can, but probably shouldn't), make sure they live in Packages/ApplySyntax. If you download and extract a compressed archive from GitHub, the directory will be facelessuser-ApplySyntax. Remove facelessuser-.

Courtesy for installation steps: https://github.com/facelessuser/ApplySyntax/blob/master/readme.md

N.B: I installed it and now the *.ctp files are displayed with proper syntax-highlighting for me.

Update:

In Sublime Text 3, you don't have to use the plugin, you can use the following solution: https://stackoverflow.com/a/35297789/749232

like image 156
saji89 Avatar answered Sep 22 '22 16:09

saji89


NO NEED FOR A PLUGIN NOW!

In the latest version of SublimeText 3 (at least), you can open a CTP file, then:

View -> Syntax -> Open all current extension as -> PHP

Then just close your open files, and when you re-open them, they'll be highlighted like the language you chose for that extension.

like image 24
Dave Avatar answered Sep 21 '22 16:09

Dave