ejscanjscanjs-view

View helper in EJS / JMVC / canJs


Planning to use view helpers in my JMVC application. Tried to implement select_tag helper function in my ejs file but failed to obtain required results. Below is the code

In Controller :

this.choice= [{value: 1,    text: 'First Choice'}, 
              {value: 2,    text: 'Second Choice'} ];                
this.element.html(initView({choice:this.choice}));

In Ejs file :

<%= select_tag('elementId', 1,  this.choice) %>

Reference https://code.google.com/p/embeddedjavascript/wiki/ViewHelpers

Do we need to steal any packages ? is there any sample code ?


Solution

  • To get access to the helpers I did three things...

    1. I updated the first line of file jquerypp/view/helpers/helpers.js from:

      steal('jquerypp/view/ejs').then(function($){
      

      to

      steal('jquerypp/view/ejs').then(function(){
      
    2. I stole 'jquerypp/view/helpers' in the controller.

    3. Finally, in the ejs instead of

      <%= select_tag('elementId', 1,  this.choice) %>
      

      I used

      <%== select_tag('elementId', 1,  this.choice) %>
      

    to force ejs to render the select block as part of the page instead of rendering an escaped quoted version.