Issue 58: Add a LISP-style "let" statement
Status:  New
Owner: ----
Reported by elij...@gmail.com, Nov 4, 2010
Sometimes it would be nice to have an explicit way of assigning the value of one name to another so that, in situations where there is a name collision, the template writer could be specific about choosing which name they wanted rather than not have access to names higher up in the scope chain.  A good example of such a collision is detailed in issue #52 with the name "url".

I think a "let" statement, such as LISP's, would work well here.

For example, here's the template and expansion dictionary from issue #52 and the documentation, with a "let" statement added.

{.section songs}
  <h2>Songs in '{playlist-name}'</h2>
  {.let playlist-url url}
    <table width="100%">
    {.repeated section @}
      <tr>
        <td><a href="{url-base|htmltag}{url|htmltag}">Play</a>
        <td><i>{title}</i></td>
        <td>{artist}</td>
        <td><a href="{url-base|htmltag}{playlist-url|htmltag}">Link to playlist</a>
      </tr>
    {.end}
    </table>
  {.end}
{.or}
  <p><em>(No page content matches)</em></p>
{.end}

... combined with a data dictionary ...

{
  "url": "happy!",
  "url-base": "http://example.com/music/", 
  "playlist-name": "Epic Playlist", 
  "songs": [
    {
      "artist": "Grayceon", 
      "title": "Sounds Like Thunder"
    }, 
    {
      "url": "2.mp3", 
      "artist": "Thou", 
      "title": "Their Hooves Carve Craters in the Earth"
    }
  ]
}

Perhaps it is not the best example to illustrate the usefulness of this language addition, but hopefully it is clear that it does solve an actual problem.