Syntax
Here is the syntax of the yuppsy tempalte system:
Naming convention:
{object:ObjectType}
{:PropertyName}
{block:BlockName}
{:OtherPropertyName}
{/block:BlockName}
{/object:ObjectType}
object - Is a convention to define the object root and it's used to contain the template block and get the data from the system based on the ObjectType name.
ObjectType - The name of the object, this is used as a holder for the template block, it is also used to get the correct data from the system. Like for Property object, the ObjectType is "Property", for Agent object, the ObjectType is "DirectoryItem", etc. and they pull data from the system based on the ObjectType name.
block - Is a convention to define a sub object, this is used to contain data depending of the ObjectType's structure in the system.
BlockName - The name of the block, depending of the ObjectType structure, the block name is used to get the correct data from the system.
Object
The obejct is the base module of the template. The template can have multiple modules of the same type, but they can have different names.
{object:ObjectType}
- the contents will be rendered only if the object exists
{/object:ObjectType}
An object can have sub objects, they are called blocks. Also an object or block can have properties.
{object:ObjectType}
{:ObjectPropertyName}
{block:BlockName}
{:BlockPropertyName}
{/block:BlockName}
{/object:ObjectType}
Sub objects, blocks, can have be used on contexts.
Consider the following object structure, if one wants to access Property.Location inside StoryItem you will have to use context
{object:Property}
{block:Location}
{:Address}
{:City}
{:State}
{:Zip}
{/block:Location}
{block:Story}
{block:StoryItem}
{:Id}
{:Order}
{:StoryItemText}
{/block:StoryItem}
{/block:Story}
{/object:Property}
The context with the name root will give you access to the whole level of the Property. Context can have any name you like, we use root in this example.
{object:Property context="root"}
{block:Location}
{:Address}
{:City}
{:State}
{:Zip}
{/block:Location}
{block:Story}
{block:StoryItem}
{:Id}
{:Order}
{:StoryItemText}
{@root:block:Location}
{:Address}
{:City}
{:State}
{:Zip}
{/@root:block:Location}
{/block:StoryItem}
{/block:Story}
{/object:Property}
Context blocks can have null checks.
{object:Property context="root"}
{block:Location}
{:Address}
{:City}
{:State}
{:Zip}
{/block:Location}
{block:Story}
{block:StoryItem}
{:Id}
{:Order}
{:StoryItemText}
{@root:block:Location}
{:Address}
{:City}
{:State}
{:Zip}
{~@root:block:Location}
renders if no Location is available
{/@root:block:Location}
{/block:StoryItem}
{/block:Story}
{/object:Property}
You CANNOT access contexts outside of the object bounds.
Consider the following object structure
{object:Property}
{block:Location}
{:Address}
{:City}
{:State}
{:Zip}
{/block:Location}
{block:Story}
{block:StoryItem}
{:Id}
{:Order}
{:StoryItemText}
{/block:StoryItem}
{/block:Story}
{/object:Property}
If one wants to access :Address inside StoryItem and you add context to block:Location, it will NOT work, because @location context is
used outside of the block:Location bounds. Context gives you access to lower levels in the object structure.
{object:Property}
{block:Location context="location"}
{:Address}
{:City}
{:State}
{:Zip}
{/block:Location}
{block:Story}
{block:StoryItem}
{:Id}
{:Order}
{:StoryItemText}
{@location:Address} - will NOT be rendered, the value is empty
{/block:StoryItem}
{/block:Story}
{/object:Property}
To access {:Address} do the following:
{object:Property context="prop"}
{block:Story}
{block:StoryItem}
{:Id}
{:Order}
{:StoryItemText}
{@prop:block:Location}
{:Address} - will render
{/@prop:block:Location}
{/block:StoryItem}
{/block:Story}
{/object:Property}
@prop:block:Location is in the object:Property object domain.
Objects, blocks and properties can have attributes.
{object:ObjectType attribute="attribute_value"}
{:Property propAttribute="attribute_value"}
{/object:ObjectType}
Conditional:
{object:ObjectType}
- if the object exists
{~object:ObjectType} - optional
- object is null or undefined
{/object:ObjectType}
Object context:
You can reference an object up in the hierarchy bu adding a context name.
{object:ObjectType}
{block:Name context="blockContext"}
{global:ObjectName}
{block:GlobalBlockName}
{@blockContext:SomePropertyName}
{/block:GlobalBlockName}
{/global:ObjectName}
{/block:Name}
{/object:ObjectType}
Boolean property:
Property checking that is evaluating as a boolean and if TRUE is replaced by the value attribute
{?:Name value="the_value" /}
Or with context
{?@context:Name value="the_value" /}
Property checking that is evaluating as a boolean and if FALSE is replaced by the value attribute
{!:Name value="the_value" /}
Or with context
{!@context:Name value="the_value" /}
Property checking that is evaluating as a TRUE and is acting as block
{?:Name}
- Name is evaluated as TRUE
{~:Name} - optional
- ELSE content
{/:Name}
Or with context
{?@context:Name}
- Name is evaluated as TRUE
{~@context:Name} - optional
- ELSE content
{/@context:Name}
Property checking that is evaluating as a FALSE and is acting as block
{!:Name}
- Name is evaluated as FALSE
{~:Name} - optional
- ELSE content
{/:Name}
Or with context
{!@context:Name}
- Name is evaluated as FALSE
{~@context:Name} - optional
- ELSE content
{/@context:Name}
Check if the value of "Name" property is EQUAL with the value of "value" (the_value in this case) then execute the block.
{=:Name value="the_value" type="the_value_type"}
- Name is evaluated as TRUE
{~:Name} - optional
- ELSE content
{/:Name}
- "type" is optional, default is "string", possible values are: "number" and "string"
Or with context
{=@context:Name value="the_value" type="the_value_type"}
- Name is evaluated as TRUE
{~@context:Name} - optional
- ELSE content
{/@context:Name}
Utilities for lists
Chunk is good when you have a list and you want to chunk it out, like:
- see Chunk example
NOTE: list[] -> list[][] with the chunk size as the sub array size
{*Chunk size="chunk_size"}
List item block
{/*Chunk}
- chunk_size is the number of items in chunck
Items at index.
{$IsIndex index="X"}
If the index of the array is X then this will render
{~$IsIndex} - optional
else this content will be rendered
{/$IsIndex}
{$IsIndex index="X" value="some value for even index" else="value for odd index" /}
- OR -
{$IsIndex gt="X"}
If the index of the array is X then this will render
{~$IsIndex} - optional
else this content will be rendered
{/$IsIndex}
{$IsIndex gt="X" value="some value for even index" else="value for odd index" /}
- OR -
{$IsIndex lt="X"}
If the index of the array is X then this will render
{~$IsIndex} - optional
else this content will be rendered
{/$IsIndex}
{$IsIndex lt="X" value="some value for even index" else="value for odd index" /}
etc ...
Supported attributes:
- index - equal
- eq - equal
- ne - not equal
- gte - greater than or equal
- gt - greater than
- lte - less than or equal
- lt - less than
Even items.
{$Even}
if the list index is even then content will be rendered
{~$Even} - optional
else this content will be rendered
{/$Even}
{$Even value="some value for even index" else="value for odd index" /}
Odd items.
{$Odd}
if the list index is even then content will be rendered
{~$Odd} - optional
else this content will be rendered
{/$Odd}
{$Odd value="some value for even index" else="value for odd index" /}
Every X item.
NOTE: "nth" defaults to 3, also X is the index value, so if it's 3 and you have index starting from 0 to 4 when item with index 3 will
render then that is when the block be true, so nth is the index
NOTE: I could change the way it works to be based on item no. that like every 3rd item, not index
{$Every nth="X"}
if the list index is the X-th element then content will render
{~$Every} - optional
else this content will be rendered
{/$Every}
{$Every nth="X" value="some value for even index" else="value for odd index" /}
First X items
{$First count="X"}
if the list index is the X-th element then content will render
{~$First} - optional
else this content will be rendered
{/$First}
{$First count="X" value="some value for even index" else="value for odd index" /}
Last X items
{$Last count="X"}
- if the list index is the X-th element then content will render
{~$Last} - optional
- else this content will be rendered
{/$Last}
{Last count="X" value="renders for even index" else="renders for odd index" /}
Length check of the array.
{$Length eq="some_int"}
- renders only if the length of the current list is "some_int" value
{~$Length} - optional
- else will render this
{/$Length}
OR
{$Length eq="some_int" value="renders for true" else="else renders this" /}
Supported attributes:
- eq - equal
- ne - not equal
- gte - greater than or equal
- gt - greater than
- lte - less than or equal
- lt - less than
Output number of items in a list
Count MUST be inside the list to get the value.
{$Count /}
OR
{$Count add="3" /} - will output number of items plus 3
Supported attributes:
- add - add the number you set
- subtract - subtract the number you set
Join, will add the current block value or the attribute "value" to the list items
{$Join} any value {/$Join}
{$Join value="any value" /}
- if Tag is an array of strings like ["this", "is", "a tag"]
{block:Tag}{:Value}{$Join}, {/$Join}{/block:Tag}
- will result in: this, is, a tag
e.g. if Tag is an array of strings like ["this", "is", "a tag"]
{block:Tag}{:Value}{$Join}, {/$Join}{/block:Tag}
will result in: this, is, a tag
Index will output the index number of the list
{$Index /}
OR
{$Index add="1" /} - will output the current index plus 1
Supported attributes:
- add - add the number you set
- subtract - subtract the number you set
Text transform attributes
textTransform: tolowercase, touppercase, totitlecase
{:SomePropertyName textTransform="tolowercase"}
textTrim: trimleft, trimright, trim
{:SomePropertyName textTrim="trim"}
currency: any string
{:SomeNumber currency="$"}
Math attributes
- Supported: add, subtract, multiply, divide, mod, abs, floor, and ceil
- for abs, floor, and ceil value will be ignored
- if applied to none numeric values, the result will be NaN
- if multiple math attributes are applied, the order of execution is from left to right, so the first attribute will be executed first, then the second, and so on.
{:Longitude abs floor subtract=2 multiply=7 mod=3 divide=2}
UniqueId attribute
Make an unique ID
- To create new ids you need to change the property nane (PropertyName) to a new one. To access the same unique id you need to use the same property name (PropertyName) in the template. Every time you use {:PropertyName uniqueId}, same id will output.
- Size is optional, if you set it, the unique id will be generated with the size you set, otherwise it will be generated with a default size of 1 characters incrementing number, so the first unique id will be 1, the second will be 2, etc.
- Min size is 6, Max size is 20 chars.
{:PropertyName uniqueId}
OR
{:PropertyName uId}
will produce:
PropertyName_1
and
{:PropertyName uniqueId=8}
OR
{:PropertyName uId=8}
will produce:
PropertyName_okxxs7tq