Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

Posts Tagged ‘brail macros

Brail Daily Use Macros #2

with 2 comments

Imagine you had to associate multiple skill to your “Profile”

Multiple skill

Suppose we have the following Profile & Skill class

class Profile {
  public virtual int Id { get; set; }
  public virtual string Name { get; set; }
  //.... other properties as necessary
  public virtual IList<Skill> Skills { get;set; }
}

// a lookup class per say
class Skill {
  public virtual int Id { get;set; }
  public virtual Profile { get; set; }
  public virtual string Title { get; set; }
}

Assume that we know how to apply AR attribute on these two class make it persist able to a database. The important thing is Profile has many Skills that all you have to concentrate on right now.

Ok ! today recipe is to generate UI with checkbox which allow user to tick and save the choices without any hassle. With the help of FormHelper method YES, WE CAN

<%
list = Form.CreateCheckboxFieldList("p.Skills", skills, {@text:'Title', @value:'Id'})
// we need a loop
for item in list:
%>
  ${list.Item()}  ${item.ToString()}
<%
end
%>

Don’t panic let me explain a bit ${list.Item()} will generate individual html checkbox where ${item.ToString()} will generate a label for each one.

Advertisements

Written by Chorn Sokun

March 16, 2009 at 5:00 pm

Brail Daily Use Macros

with one comment

If you are DRY then try these macros in your *.brail

<% OutputSubView("_list") %>

Passing some variable to sub-view

<% OutputSubView("_list", {@students: studentList}) %>

but if you work with *.brailjs then you would love

Page.ReplaceHtml("#domElementId", {@Partial: '_list'})

Why do I choose brail?

  • it compile => performance gain
  • easy to create additional template processing macros
  • it just Boo !

until next time.

Written by Chorn Sokun

March 10, 2009 at 10:22 am

Posted in Castle, Tips & Tricks

Tagged with