---
title: "Freemarker Built-ins for hashes"
author: "as619864232"
date: "2013-01-22T10:41:36Z"
tags: []
categories: ["Web前端"]
slug: "freemarker-built-ins-for-hashes"
draft: false
lastmod: "2013-01-22T10:41:36Z"
id: 1773588
url: "https://ears.iteye.com/blog/1773588"
---

# Built-ins for hashes

**Page Contents**

- [keys](http://freemarker.sourceforge.net/docs/ref_builtins_hash.html#ref_builtin_keys)
- [values](http://freemarker.sourceforge.net/docs/ref_builtins_hash.html#ref_builtin_values)

[]()

## []()keys

A sequence that contains all the lookup keys in the hash. Note that not all hashes support this (ask the programmer if a certain hash allows this or not).

![](http://freemarker.sourceforge.net/docs/docgen-resources/img/none.gif) ![](http://freemarker.sourceforge.net/docs/docgen-resources/img/none.gif) ![](http://freemarker.sourceforge.net/docs/docgen-resources/img/none.gif) ![](http://freemarker.sourceforge.net/docs/docgen-resources/img/none.gif)

```
<#assign h = {"name":"mouse", "price":50}>
<#assign keys = h?keys>
<#list keys as key>${key} = ${h[key]}; </#list> 
```

![](http://freemarker.sourceforge.net/docs/docgen-resources/img/none.gif) ![](http://freemarker.sourceforge.net/docs/docgen-resources/img/none.gif) ![](http://freemarker.sourceforge.net/docs/docgen-resources/img/none.gif) ![](http://freemarker.sourceforge.net/docs/docgen-resources/img/none.gif)

Output:

![](http://freemarker.sourceforge.net/docs/docgen-resources/img/none.gif) ![](http://freemarker.sourceforge.net/docs/docgen-resources/img/none.gif) ![](http://freemarker.sourceforge.net/docs/docgen-resources/img/none.gif) ![](http://freemarker.sourceforge.net/docs/docgen-resources/img/none.gif)

```
name = mouse; price = 50; 
```

![](http://freemarker.sourceforge.net/docs/docgen-resources/img/none.gif) ![](http://freemarker.sourceforge.net/docs/docgen-resources/img/none.gif) ![](http://freemarker.sourceforge.net/docs/docgen-resources/img/none.gif) ![](http://freemarker.sourceforge.net/docs/docgen-resources/img/none.gif)

Since hashes do not define an order for their subvariables in general, the order in which key names are returned can be arbitrary. However, some hashes maintain a meaningful order (ask the programmer if a certain hash does that or not). For example, hashes created with the above `{...}` syntax preserve the same order as you have specified the subvariables.

## []()values

A sequence that contains all the variables in the hash. Note that not all hashes support this (ask the programmer if a certain hash allows this or not).

As of the order in which the values are returned, the same applies as with the `keys` built-in; see there.