baryshev / ect

Fastest JavaScript template engine with embedded CoffeeScript syntax
http://ectjs.com
MIT License
625 stars 69 forks source link

?= syntax, dealing with undefined values #59

Closed dead1 closed 10 years ago

dead1 commented 10 years ago

I tried to do %-(@opt_time_groups[key].name?=123)% or <%-(@opt_time_groups[key].name || 123)%> but have got no success and "TypeError: Cannot read property 'name' of undefined" error. Could you tell me please, how do I intended to do that thing in ECT?

Full code is:

<%for key of @opt_time_groups.concat([1..3]) : %>
  <tr>
    <td>
      <input 
        type="text" 
        name="opt_time_groups[<%-key%>][name]" 
        value="<%-@opt_time_groups[key].name || 123%>"
        />
    </td>
  </tr>
<%end%>

Obviously, it's my mistake. Not an issue. The solution is:

<%-if @opt_time_groups[key] then @opt_time_groups[key].name else 123%>