-
Notifications
You must be signed in to change notification settings - Fork 10
templates
templates are defined in a normal text file. list below are some of the features of the templates
Styles are associated to a template by linking the style of the template tag to the name of the style in the styles file.
For more information about styles see Styles
Example: In the example below the style of the template tag .core tells the engine to use the .core style group in the styles file.
template.core
{
list down
{
text6 'this is text1'
text6 'this is text2'
}
}
- Comments are in the form of // just like in java.
- Multi-line comments /* */ are NOT supported.
template.core
{
list down
{
// this is comment 1
text6 'this is text1'
// this is comment 2
text6 'this is text2'
}
}
A nice feature of the template is to provide a "setup" section which allows you to define variables such as arrays and dictionaries for the purpose of loading up some sample data for the template.
setup
{
// 2. configures the data during design mode
set events = [
{ DayName : 'MON', Title: 'Event 1', Location: 'Conference room a', StartTime: '1:30 pm' },
{ DayName : 'TUE', Title: 'Event 2', Location: 'Conference room b', StartTime: '2:30 pm' },
{ DayName : 'WED', Title: 'Event 3', Location: 'Conference room c', StartTime: '3:30 pm' },
{ DayName : 'THU', Title: 'Event 4', Location: 'Conference room d', StartTime: '4:30 pm' },
{ DayName : 'FRI', Title: 'Event 5', Location: 'Conference room e', StartTime: '5:30 pm' },
]
}
template.core
{
// display the test data here...
}
You can use pre-processor directives ( like #define in c# or c++ ) This comes in handy for testing purposes.
example : the example below defines test-data and only loads sample data if test-data is defined.
define test-data
setup
{
// 2. configures the data during design mode
ifdef test-data
set events = [
{ DayName : 'MON', Title: 'Event 1', Location: 'Conference room a', StartTime: '1:30 pm' },
{ DayName : 'TUE', Title: 'Event 2', Location: 'Conference room b', StartTime: '2:30 pm' },
{ DayName : 'WED', Title: 'Event 3', Location: 'Conference room c', StartTime: '3:30 pm' },
{ DayName : 'THU', Title: 'Event 4', Location: 'Conference room d', StartTime: '4:30 pm' },
{ DayName : 'FRI', Title: 'Event 5', Location: 'Conference room e', StartTime: '5:30 pm' },
]
endif
}
template.core
{
// display the test data here...
}
Using the example above ( loading some sample data ), we can now bind that data to controls and even loop through collections. For more information on how to bind see the Data wiki page
define test-data
setup
{
// 2. configures the data during design mode
ifdef test-data
set events = [
{ DayName : 'MON', Title: 'Event 1', Location: 'Conference room a', StartTime: '1:30 pm' },
{ DayName : 'TUE', Title: 'Event 2', Location: 'Conference room b', StartTime: '2:30 pm' },
{ DayName : 'WED', Title: 'Event 3', Location: 'Conference room c', StartTime: '3:30 pm' },
{ DayName : 'THU', Title: 'Event 4', Location: 'Conference room d', StartTime: '4:30 pm' },
{ DayName : 'FRI', Title: 'Event 5', Location: 'Conference room e', StartTime: '5:30 pm' },
]
endif
}
template.core
{
list:root down
{
@each( event in events )
{
list down
{
text6.accent @event.Title
text6.accent @event.DayName
text6.accent @event.StartTime
text6.accent @event.Location
}
}
}
}
Ultimately the data for the template comes from your application. In order to supply the data for the template through code you would do the following:
// 1. Get the content of the template from your asset file.
// assume a 'getTemplateContent' method exists gets a file content from your app
String templateContent = getTemplateContent("events_for_week.txt");
// 2. Get the template service
TemplateService svc = new TemplateService();
// 3. build a list of events for the template
// assume a 'getEventsForThisWeek' method exists to return some events date
List<Event> events = getEventsForThisWeek();
// 4. Now supply the data to the template engine
svc.getData().put("days", events);
// 5. Now execute the template and get the control.
TemplateView tview = svc.executeTemplate(templateContent);