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

# Built-ins for booleans

## []()string (when used with a boolean value)

Converts a boolean to a string. You can use it in two ways:

- As `foo?string`: This will convert the boolean to string using the default strings for representing true and false values. By default, true is rendered as `"true"` and false is rendered as `"false"`. This is mostly useful if you generate source code with FreeMarker, since the values are not locale (language, country) sensitive. To change these default strings, you can use the `boolean_format` [setting](http://freemarker.sourceforge.net/docs/ref_directive_setting.html). Note, that if the variable is multi-type variable that is both boolean and string, then the string value of the variable will be returned.
- As `foo?string("yes", "no")`: This will return the first parameter (here: `"yes"`) if the boolean is true, otherwise the second parameter (here: `"no"`). Note that the return value is always a string; if the parameters were numbers, they would be converted to strings first.