{"action":"closed","issue":{"url":"https://api.github.com/repos/mbosecke/pebble/issues/94","labels_url":"https://api.github.com/repos/mbosecke/pebble/issues/94/labels{/name}","comments_url":"https://api.github.com/repos/mbosecke/pebble/issues/94/comments","events_url":"https://api.github.com/repos/mbosecke/pebble/issues/94/events","html_url":"https://github.com/mbosecke/pebble/issues/94","id":104995031,"number":94,"title":"How to access the contents of a Map from a template?","user":{"login":"acrispino","id":1243207,"avatar_url":"https://avatars.githubusercontent.com/u/1243207?v=3","gravatar_id":"","url":"https://api.github.com/users/acrispino","html_url":"https://github.com/acrispino","followers_url":"https://api.github.com/users/acrispino/followers","following_url":"https://api.github.com/users/acrispino/following{/other_user}","gists_url":"https://api.github.com/users/acrispino/gists{/gist_id}","starred_url":"https://api.github.com/users/acrispino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/acrispino/subscriptions","organizations_url":"https://api.github.com/users/acrispino/orgs","repos_url":"https://api.github.com/users/acrispino/repos","events_url":"https://api.github.com/users/acrispino/events{/privacy}","received_events_url":"https://api.github.com/users/acrispino/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-09-05T01:32:33Z","updated_at":"2015-09-07T02:38:20Z","closed_at":"2015-09-07T02:38:20Z","body":"Hello, I'd like to access the contents of a Map using a key obtained by looping over another collection. But I'm not sure how to accomplish that. I can't use the subscript notation (\"Only strings and numbers allowed within square brackets\") but I can't seem to use Map.get() either. \r\n\r\nI've included some contrived example code to show you what I'm after.\r\n\r\nI'm using pebble 1.5.2\r\n\r\n```Java\r\npublic class Application {\r\n  public static void main(String[] args) throws IOException, PebbleException {\r\n    PebbleEngine engine = new PebbleEngine();\r\n    engine.setStrictVariables(true);\r\n    PebbleTemplate compiledTemplate = engine.getTemplate(\"home.html\");\r\n    Map<String, Object> context = new HashMap<>();\r\n\r\n    Map<Integer, User> usersById = new HashMap<>();\r\n    usersById.put(1, new User(\"John\", \"Doe\"));\r\n    usersById.put(2, new User(\"Jane\", \"Doe\"));\r\n    context.put(\"usersById\", usersById);\r\n\r\n    List<Integer> userIds = new ArrayList<>();\r\n    userIds.add(1);\r\n    userIds.add(2);\r\n    context.put(\"userIds\", userIds);\r\n\r\n    Writer writer = new StringWriter();\r\n    compiledTemplate.evaluate(writer, context);\r\n    System.out.println(writer.toString());\r\n  }\r\n\r\n  public static class User {\r\n    private final String firstName;\r\n    private final String lastName;\r\n\r\n    public User(String firstName, String lastName) {\r\n      this.firstName = firstName;\r\n      this.lastName = lastName;\r\n    }\r\n\r\n    public String getFirstName() {\r\n      return firstName;\r\n    }\r\n\r\n    public String getLastName() {\r\n      return lastName;\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n```\r\n<!DOCTYPE html>\r\n<html>\r\n<head>\r\n  <title>TEST</title>\r\n</head>\r\n<body>\r\n<h1>Users</h1>\r\n<ul>\r\n  {% for userId in userIds %}\r\n    <li>{{ userId }}: {{ usersById.get(userId).getFirstName() }}</li>\r\n\r\n    {# Not allowed #}\r\n    {# <li>{{ userId }}: {{ usersById[userId].getFirstName() }}</li> #}\r\n  {% endfor %}\r\n</ul>\r\n</body>\r\n</html>\r\n```\r\n\r\nWith the above code and template I get this exception:\r\n```\r\nException in thread \"main\" com.mitchellbosecke.pebble.error.AttributeNotFoundException: Attribute [get] of [java.util.HashMap] does not exist or can not be accessed and strict variables is set to true. (?:?)\r\n\tat com.mitchellbosecke.pebble.node.expression.GetAttributeExpression.evaluate(GetAttributeExpression.java:144)\r\n    ...\r\n```"}}