Skip to content
This repository was archived by the owner on Feb 26, 2019. It is now read-only.

liferay/soy-cheat-sheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 

Repository files navigation

Logo

Soy Cheat Sheet

A collection of cool hidden and not so hidden features, to be used as a quick reference so that you turn coffee into code much faster :)

Table of Contents

Namespace

{namespace foo}

See Docs

Template

/**  *  */ {template .hello}	Hello world {/template}

See Docs

Parameters

required
/**  *  */ {template .hello}	{@param name: string}	Hello {$name} {/template}
optional
/**  *  */ {template .hello}	{@param? name: string}	Hello {$name} {/template}

See Docs

Parameter Types

primitive types
string bool int float number 
other types
any ? null html 
complex types
list<Type> // List map<KeyType, ValueType> // Map [a:KeyType, b:ValueType] // Record Type1|Type2 // Union 

See Docs

Call

{call .hello}	{param name: 'Jon' /} {/call}
{call .hello}	{param name: $name /}	{param lastName: $lastName /} {/call}
{call .hello data="all" /}

See Docs

Variables

{let $name: 'Jon' /}
{let $names: [	['first': 'Jon', 'last': 'Snow'],	['first': 'Arya', 'last': 'Stark'] ] /}
kind
{let $name kind="text"}	Jon {/let}
{let $name kind="html"}	<p>Jon</p> {/let}

See Docs

Conditionals

if
{if $name}	Hello {$name} {/if}
if and
{if $name and $lastName}	Hello {$name} {$lastName} {/if}
if not
{if not $name}	Hello there {/if}
else
{if $name}	Hello {$name} {else}	Hello there {/if}
elseif
{if $gender == 'Male'}	Hello Sir {elseif $gender == 'Female'}	Hello Madam {/if}

See Docs

switch
{switch $gender} {case 'Male'} Hello Sir {case 'Female'} Hello Madam {default} Hello Human {/switch}

See Docs

elvis
Hello {$name ?: 'there'}
ternary
{$name ? 'Hello {$name}' : 'Hello there'}

See Docs

Loops

foreach
{foreach $name in $names}	Hello {$name} {/foreach}
ifempty
{foreach $name in $names}	Hello {$name} {ifempty}	Hello there {/foreach}

See Docs

Special Characters

literal
{literal}	<pre>	function() {	console.log('Hello');	}	</pre> {/literal}

See Docs

miscellaneous
{sp} // space {nil} // empty string {\n} // newline {\r} // carriage return {\t} // tab {lb} // left brace {rb} // right brace

See Docs

Functions

any
{isNonnull(value)}
string
{strContains(string, subString)}
number
{ceiling(number)} {floor(number)} {max(number, number)} {min(number, number)} {randomInt(number)} {round(number)}
foreach
{index($var)} {isFirst($var)} {isLast($var)}
list
{length(list)}
map
{augmentMap(map1, map2)} {keys(map)}

See Docs

About

A quick reference guide for Soy templates (aka. Google Closure templates)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •