Augment list of maps

33 views
Skip to first unread message

yuri.b...@gmail.com

unread,
Sep 14, 2016, 7:48:15 PM9/14/16
to Closure Templates Discuss
I have such a template. It displays a list of categories that comes to me from the server.

/*
 * List of categories
 * @param categories
 */

{template .categories}
 
<ul>
   
{foreach $category in $categories}
     
<li><a href="{$category.url}">{$category.name}</a></li>
   
{/foreach}
  </
ul>
{/template}

Here is an example of the data coming from the server.

"categories":[{
 
"id": "a",
 
"url": "#a"
}, {
  "id": "b",
 
"url": "#b"
}, {
  "id": "c",
 
"url": "#c"
}]

The difficulty is that the category names do not come from the server. I keep them in the template in order to be localized.

{let $names: [
 
"a": "Category A",
  "b": "Category B",
 
"c": "Category C"
]/}

So I need before calling the template categories augment the original list with localized names. Somethink like this:

{let $categoriesLocalized}
 
{foreach $category in $categories}
    augmentMap
($category, ["name": $names[$category.id]])
 
{/foreach}
{/
let}

{call .categories}
  
{param $categories: $categoriesLocalized /}
{/
let}


But this does not work, because all that is written inside block let becomes a string. :-(
Is there a way to dynamically create or expand the list?

Luke Sandberg

unread,
Sep 19, 2016, 3:05:06 PM9/19/16
to Closure Templates Discuss
you can't do this,  you could pass the name map down, or register a custom SoyFunction to transform the map.

--

---
You received this message because you are subscribed to the Google Groups "Closure Templates Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-templates-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages