mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
DOC: Add docs for template namespacing.
This commit is contained in:
parent
65eb0bde6a
commit
b249cc389a
@ -3,10 +3,9 @@ summary: A look at the operations, variables and language controls you can use w
|
|||||||
|
|
||||||
# Template Syntax
|
# Template Syntax
|
||||||
|
|
||||||
SilverStripe templates are plain text files that have `.ss` extension and located within the `templates` directory of
|
A template can contain any markup language (e.g HTML, CSV, JSON..) and before being rendered to the user, they're
|
||||||
a module, theme, or your `mysite` folder. A template can contain any markup language (e.g HTML, CSV, JSON..) and before
|
processed through [api:SSViewer]. This process replaces placeholders such as `$Var` with real content from your
|
||||||
being rendered to the user, they're processed through [api:SSViewer]. This process replaces placeholders such as `$Var`
|
[model](../model) and allows you to define logic controls like `<% if $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:
|
An example of a SilverStripe template is below:
|
||||||
|
|
||||||
@ -45,6 +44,17 @@ Templates can be used for more than HTML output. You can use them to output your
|
|||||||
text-based format.
|
text-based format.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
## Template file location
|
||||||
|
|
||||||
|
SilverStripe templates are plain text files that have `.ss` extension and located within the `templates` directory of
|
||||||
|
a module, theme, or your `mysite` folder.
|
||||||
|
|
||||||
|
By default, templates will have the same name as the class they are used to render. So, your Page class will
|
||||||
|
be rendered with the `templates/Page.ss` template.
|
||||||
|
|
||||||
|
When the class has a namespace, the namespace will be interpreted as subfolder within the `templates` path. For, example, the class `SilverStripe\Control\Controller` will be rendered with the
|
||||||
|
`templates/SilverStripe/Control/Controller.ss` template.
|
||||||
|
|
||||||
## Variables
|
## Variables
|
||||||
|
|
||||||
Variables are placeholders that will be replaced with data from the [DataModel](../model/) or the current
|
Variables are placeholders that will be replaced with data from the [DataModel](../model/) or the current
|
||||||
@ -190,11 +200,15 @@ You can use inequalities like `<`, `<=`, `>`, `>=` to compare numbers.
|
|||||||
|
|
||||||
## Includes
|
## Includes
|
||||||
|
|
||||||
Within SilverStripe templates we have the ability to include other templates from the `template/Includes` directory
|
Within SilverStripe templates we have the ability to include other templates using the `<% include %>` tag. The includes
|
||||||
using the `<% include %>` tag.
|
will be searched for using the same filename look-up rules as a regular template, so this will include
|
||||||
|
`templates/Includes/Sidebar.ss`
|
||||||
|
|
||||||
:::ss
|
:::ss
|
||||||
<% include SideBar %>
|
<% include Includes\SideBar %>
|
||||||
|
|
||||||
|
Note that in SilverStripe 3, you didn't have to specify a namespace in your `include` tag, as the template engine didn't
|
||||||
|
use namespaces. As of SilverStripe 4, the template namespaces need to match the folder structure of your template files.
|
||||||
|
|
||||||
The `include` tag can be particularly helpful for nested functionality and breaking large templates up. In this example,
|
The `include` tag can be particularly helpful for nested functionality and breaking large templates up. In this example,
|
||||||
the include only happens if the user is logged in.
|
the include only happens if the user is logged in.
|
||||||
|
@ -101,3 +101,7 @@ footer and navigation will remain the same and we don't want to replicate this w
|
|||||||
<blink>Hi!</blink>
|
<blink>Hi!</blink>
|
||||||
|
|
||||||
|
|
||||||
|
If your classes have in a namespace, the Layout folder will be a found inside of the appropriate namespace folder.
|
||||||
|
|
||||||
|
For example, the layout template for `SilverStripe\Control\Controller` will be
|
||||||
|
found at `templates/SilverStripe/Control/Layout/Controller.ss`.
|
||||||
|
Loading…
Reference in New Issue
Block a user