title: Template Syntax summary: A look at the operations, variables and language controls you can use within templates. # Template Syntax SilverStripe templates are plain text files that have `.ss` extension and located within the `templates` directory of a module, theme, or your `mysite` folder. A template can contain any markup language (e.g HTML, CSV, JSON..) and before being rendered to the user, they're processed through [api:SSViewer]. This process replaces placeholders such as `$Var` with real content from your [model](../model) and allows you to define logic controls like `<% if $Var %>`. An example of a SilverStripe template is below: **mysite/templates/Page.ss** :::ss
<% base_tag %>Welcome $FirstName $Surname.
<% end_with %> <% if $Dishes %>You are coming from $UsersIpAddress.
The variable's that can be used in a template vary based on the object currently in [scope](#scope). Scope defines what object the methods get called on. For the standard `Page.ss` template the scope is the current [api:Page_Controller] class. This object gives you access to all the database fields on [api:Page_Controller], its corresponding [api:Page] record and any subclasses of those two. **mysite/code/Layout/Page.ss** :::ss $Title // returns the page `Title` property $Content // returns the page `Content` property ## Conditional Logic The simplest conditional block is to check for the presence of a value (does not equal 0, null, false). :::ss <% if $CurrentMember %>You are logged in as $CurrentMember.FirstName $CurrentMember.Surname.
<% end_if %> A conditional can also check for a value other than falsey. :::ss <% if $MyDinner == "kipper" %> Yummy, kipper for tea. <% end_if %>Page '$Title' is a child of '$Up.Title'
<% loop $Children %>Page '$Title' is a grandchild of '$Up.Up.Title'
<% end_loop %> <% end_loop %> Given the following structure, it will output the text. My Page | +-+ Child 1 | | | +- Grandchild 1 | +-+ Child 2 Children of 'My Page' Page 'Child 1' is a child of 'My Page' Page 'Grandchild 1' is a grandchild of 'My Page' Page 'Child 2' is a child of 'MyPage' #### Top While `$Up` provides us a way to go up one level of scope, `$Top` is a shortcut to jump to the top most scope of the page. The previous example could be rewritten to use the following syntax. :::ssPage '$Title' is a child of '$Top.Title'
<% loop $Children %>Page '$Title' is a grandchild of '$Top.Title'
<% end_loop %> <% end_loop %> ### With The `<% with %>` tag lets you change into a new scope. Consider the following example: :::ss <% with $CurrentMember %> Hello $FirstName, welcome back. Your current balance is $Balance. <% end_with %> Outside the `<% with %>.`, we are in the page scope. Inside it, we are in the scope of `$CurrentMember` object. We can refer directly to properties and methods of the [api:Member] object. `$FirstName` inside the scope is equivalent to `$CurrentMember.FirstName`.