Sublime Forum

When in Rails - why does if <tab> generate a php snippet?

#1

When I’m working on a .html.erb file in rails and I type: if <tab>
I get a php snippet as follows: [code]<?php if (condition): ?>

<?php endif ?>[/code]

Any ideas why? I’m new to Sublime - awesome so far just trying to get the hang of it.

Also, on a related note, what is the snippet for generating an open and close erb tag <%= %>
Either with or without the “=” sign?

And is there an easy to view all the snippets along with their tab completion keys other than going into the filesystem and opening up each .snippet file?

0 Likes

PHP snippets in default HTML
#2

Same problem here. In a file named example.html.erb using “HTML (Rails)” when I type "if " it returns a PHP snippet when it should be Ruby.
I’d normally just remove the PHP snippets but I have to maintain a legacy PHP app too.

Any help appreciated :smile:

0 Likes

#3

Not sure about the first one, but I created a snippet that works well for <%= %> and <% %> tags.

<snippet>
	<content><![CDATA[<%${1:=} $2 %>]]></content>
	<tabTrigger>&lt;</tabTrigger>
</snippet>

If I don’t need the tag to output, I can just backspace the ‘=’ after the first tab and then tab again to the middle; otherwise, if I do need the output, I just double-tab and I’m all set.

Hope this helps.

0 Likes

#4

I’m getting PHP snippets showing in a html.erb file as well.

Thanks thetristan for the snippet. It was on my list of things to fix in my ST2 setup before I buy a license.

Using dev build 2207 and the context ST2 is using is “HTML (Rails)” so I don’t know why PHP snippets are showing.

I’m assuming I could just delete my php snippets but I would prefer to not have to do that.

0 Likes

#5

the problem is the scope[1] of the PHP snippets. For them it is ‘text.html - source’. An .html.erb file has the scope ‘text.html.ruby’, this is included in the PHP snippets’ scope.

I would consider this a bug, since I find it not useful to litter all text.html.* scopes with PHP snippets and suggest to limit their scope to text.html.php.

[1] to find out the scope use ScopeHunter (available via Package Control)

0 Likes

#6

[quote=“tkab”]the problem is the scope[1] of the PHP snippets. For them it is ‘text.html - source’. An .html.erb file has the scope ‘text.html.ruby’, this is included in the PHP snippets’ scope.

I would consider this a bug, since I find it not useful to litter all text.html.* scopes with PHP snippets and suggest to limit their scope to text.html.php.

[1] to find out the scope use ScopeHunter (available via Package Control)[/quote]

This is definitely the issue.

Adding a new Ruby/Rails ‘else’ snippet isn’t very helpful, because then ST2 just prompts for which snippet to use. It seems like moving/removing the PHP folder (or just the offending snippets), then creating custom Ruby/Rails snippets is the only workaround until this bug is fixed.

Edit:
Another possible workaround might be to search out all instances of “text.html” in the ~/Library/Application Support/Sublime Text 2/Packages/PHP folder and replace them with “text.php”.

0 Likes

#7

Has there been any movement on this issue? will it be fixed in a future release?

0 Likes

#8

I also have the same problem.

It’s definitevly a bug, more if the workaround is to edit the app contents.

0 Likes