playframework / playframework/twirl

Document `var` and special behaviour of toplevel definitions for each scope

Open
#1,095 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
561
Forks
118
Avg merge
1d 15h
Merged PRs (30d)
29

Description

  1. Document var

  2. Not just for var, but for val and def:

@val val1 = @{ "value1" }
@if(secondCondition == 1) {
    @val1 // This will also print shadow_value1 even thought it will be defined afterwards
    @val val1 = @{ "shadow_value1" }
    @val1
}

This is because in twirl all @... = (which define a def and does not reassign a var), @var foo =... and @[lazy] val foo ... are moved to the top of the current (pseudo template) (code) block. This is just how twirl works and can not be changed without more or less totally rewriting twirl. So let's document that behaviour. Also see tests, there a lots of example for that.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing tests mentioned in the issue, especially their examples of var, val, def, and nested scopes. Locate the documentation section covering template definitions, explain that these definitions are moved to the top of the current pseudo-template block, and verify that the documented examples match the tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.