blob: 140dff3aa29f892589647a2e5c5da3f544fe11b5 [file] [log] [blame]
<#--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<title>FreeMarker: Switch-Case Test</title>
</head>
<body>
<p>Here we iterate over a list of animals.</p>
<#assign animalList = [ "aardvark", "kiwi", "gecko", "cat", "dog", "elephant",
"squirrel", "zebra" ]>
<#assign favoriteAnimal = "kiwi">
<#foreach animal in animalList>
<p>Animal is: ${animal}.<br />
<#switch animal>
<#case "zebra">
This is the HTML for a large stripey animal.
<#case "elephant">
<#case "rhinocerous">
This is the HTML for large animals.
<#break>
<#case "squirrel">
<#case "gecko">
This is the HTML for small animals.
<#break>
<#case favoriteAnimal>
This is the HTML for the user's favorite animal.
<#break>
<#default>
This is the HTML for other animals.
<#break>
</#switch>
</p>
</#foreach>
<#-- Nesting and no-match -->
<#list [ 1, 2, 3 ] as x>
<#switch x>
<#case 1>
1
<#switch x*2>
<#case 1>
i1
<#break>
<#case 2>
i2
<#break>
<#case 3>
i3
<#break>
<#case 4>
i4
<#break>
<#case 6>
i6
<#break>
</#switch>
<#break>
<#case 2>
2
<#switch x*2>
<#case 1>
i1
<#break>
<#case 2>
i2
<#break>
<#case 3>
i3
<#break>
<#case 4>
i4
<#-- falls through -->
<#case 5>
ft
<#-- falls through -->
</#switch>
ft
<#-- falls through -->
<#case 3>
3
<#switch x*2>
<#case 1>
i1
<#break>
<#case 2>
i2
<#break>
<#case 3>
i3
<#break>
<#case 4>
i4
<#break>
<#case 6>
i6
<#break>
</#switch>
<#break>
</#switch>
</#list>
<#-- No match -->
[<#switch 213>
<#case 1>sadas
</#switch>]
<#-- Fall-through -->
<#list [ 0, 1, 2, 3, 4 ] as x>
"<#switch x><#case 1>1<#case 2>2<#case 3>3<#case 4>4</#switch>"
</#list>
<#-- Legacy parser bug: #default might not be the last, but it doesn't fall through if called directly -->
<#list [1, 2, 3, 4, 5] as x>
"<#switch x><#case 1>1<#case 2>2<#default>default<#case 4>4<#case 5>5</#switch>"
</#list>
<#-- two #default-s are parsing error -->
<@assertFails message="can only have one default"><@"<#switch 1><#case 1><#default><#default></#switch>"?interpret /></@>
</body>
</html>