Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let statement - fixes #54 #81

Closed
wants to merge 2 commits into from
Closed

Conversation

b-laporte
Copy link
Member

This pull request introduces the {let} statement that allows to create one or multiple local variables in the scope of a container block (cf. #54)

Sample from the PR:

var $set=require("hsp/$set");

# template test(m)
  {let p1=m.part1, m21=m.part2.part21.msg+"!"}
  <div>
    {let p11=p1.part11}
    Part 1.1: <span class="textValue">{p11.msg}</span><br/>
  </div>
  <div>
    Part 2.1: <span class="textValue">{m21}</span> - 
    {if !p11}
      p11 is of course not visible in the 2nd element scope
    {/if}
  </div>
  <a onclick="{updateModel()}">Change Model</a>
# /template

var model={
  part1:{
    part11: {msg: "Message 1.1"}
  },
  part2:{
    part21: {msg: "Message 2.1"}
  }
};

var count=0;
function updateModel() {
  count++;
  $set(model.part1.part11,"msg", "(1.1 update: "+count+")");
  $set(model.part2.part21,"msg", "(2.1 update: "+count+")");
}

// render template in the #output div
test(model).render("output");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant