bobomoreno
bobomoreno

Reputation: 2858

Sublimetext 2 and rails html.erb if then else issue

Love Sublime text 2, but somehow can't get it to do 'if then else' properly within an html.erb template. It correctly identifies the files as 'HTML (Rails)', but when I do 'if' followed by tab

I get:

<?php if (condition): ?>

<?php endif ?>

I've seen this reported a few other places, but not sure how to fix as new to Sublimetext. Any tips much appreciated

Upvotes: 3

Views: 1878

Answers (3)

Kevin Ansfield
Kevin Ansfield

Reputation: 2343

I added a couple of custom snippets to cover if/elsif/else in erb files.

if-erb.sublime-snippet:

<snippet>
    <content><![CDATA[<% if ${1:true} -%>]]></content>
    <tabTrigger>if</tabTrigger>
    <scope>text.html.ruby</scope>
    <description>if (ERB)</description>
</snippet>

elsif-erb.sublime-snippet

<snippet>
    <content><![CDATA[<% elsif ${1:true} -%>]]></content>
    <tabTrigger>elsif</tabTrigger>
    <scope>text.html.ruby</scope>
    <description>elsif (ERB)</description>
</snippet>

else-erb.sublime-snippet

<snippet>
    <content><![CDATA[<% else -%>]]></content>
    <tabTrigger>else</tabTrigger>
    <scope>text.html.ruby</scope>
    <description>else (ERB)</description>
</snippet>

Upvotes: 2

Michael Durrant
Michael Durrant

Reputation: 96494

You have php autocomplete there.

Install ruby and rails plugins for rails development.

More at http://linuxrails.blogspot.com/2012/05/sublime-text-2-setup-for-rails.html

Upvotes: 1

MurifoX
MurifoX

Reputation: 15089

Well, the only way i could make it work was by deleting the php snippets and adding some of my own.
Steps:
1- Go to Preferences -> Browse Packages.
2- Go inside PHP folder.
3- Delete the else/elsif snippets.
4- Create your own like the following example:

<snippet>
<content><![CDATA[
    <% else %>
  ]]></content>
<tabTrigger>else</tabTrigger>
<scope>text.html - source</scope>
</snippet>

Upvotes: 0

Related Questions