Grails Cookbook - A collection of tutorials and examples

Grails join Tag Examples

This will show examples on how to use the Grails join tag (<g:join>). This tag utilizes the Groovy join method to concatenate the toString() representation of each item in a list or collection. A custom separator can also be used for this tag.

Join Tag With Default Delimiter/Separator

Here is a sample code that uses the Grails join tag to concatenate items on a list.

<g:join in="['Apple', 'Banana', 'Carrot']" />

The output of the code above is this:
 Apple, Banana, Carrot 
Since a separator was not given, the default separator ", " (comma space) is used.

Join Tag With Custom Delimiter/Separator

Here is a modified sample code that uses Grails tag but with custom separator.

<g:join in="['Apple', 'Banana', 'Carrot']" delimiter="-" />
The output of the code is this:
Apple-Banana-Carrot 

Note that it uses the given custom delimiter "-" (dash) .

Other Grails Tag Examples



Tags: Grails Tag, join