diff --git a/docs/en/02_Developer_Guides/01_Templates/01_Syntax.md b/docs/en/02_Developer_Guides/01_Templates/01_Syntax.md index fa4bfe7d5..ad8499f5f 100644 --- a/docs/en/02_Developer_Guides/01_Templates/01_Syntax.md +++ b/docs/en/02_Developer_Guides/01_Templates/01_Syntax.md @@ -42,7 +42,7 @@ An example of a SilverStripe template is below:
Templates can be used for more than HTML output. You can use them to output your data as JSON, XML, CSV or any other -text based format. +text-based format.
## Variables @@ -92,6 +92,10 @@ Variables can come from your database fields, or custom methods you define on yo :::html

You are coming from $UsersIpAddress.

+
+ Method names that begin with `get` will automatically be resolved when their prefix is excluded. For example, the above method call `$UsersIpAddress` would also invoke a method named `getUsersIpAddress()`. +
+ 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] @@ -116,7 +120,7 @@ The simplest conditional block is to check for the presence of a value (does not

You are logged in as $CurrentMember.FirstName $CurrentMember.Surname.

<% end_if %> -A conditional can also check for a value other than falsey. +A conditional can also check for a value other than falsy. :::ss <% if $MyDinner == "kipper" %> @@ -445,18 +449,20 @@ The `<% with %>` tag lets you change into a new scope. Consider the following ex :::ss <% with $CurrentMember %> - Hello $FirstName, welcome back. Your current balance is $Balance. + Hello, $FirstName, welcome back. Your current balance is $Balance. <% end_with %> +This is functionalty the same as the following: + + :::ss + Hello, $CurrentMember.FirstName, welcome back. Yout current balance is $CurrentMember.Balance + +Notice that the first example is much tidier, as it removes the repeated use of the `$CurrentMember` accessor. 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`. -
-Why would you use `with`? This keeps the markup clean, and if the scope is a complicated expression we don't -have to repeat it on each reference of a property. -
## Comments diff --git a/docs/en/02_Developer_Guides/01_Templates/02_Common_Variables.md b/docs/en/02_Developer_Guides/01_Templates/02_Common_Variables.md index 823d162df..9f85c7e98 100644 --- a/docs/en/02_Developer_Guides/01_Templates/02_Common_Variables.md +++ b/docs/en/02_Developer_Guides/01_Templates/02_Common_Variables.md @@ -1,5 +1,5 @@ title: Common Variables -summary: Some of the common variables and methods your templates can use. +summary: Some of the common variables and methods your templates can use, including Menu, SiteConfig, and more. # Common Variables @@ -155,7 +155,7 @@ link. :::ss $LinkingMode -When looping over a list of `SiteTree` instances through a `<% loop Menu %>` or `<% loop Children %>`, `$LinkingMode` +When looping over a list of `SiteTree` instances through a `<% loop $Menu %>` or `<% loop $Children %>`, `$LinkingMode` will return context about the page relative to the currently viewed page. It can have the following values: * `link`: You are neither on this page nor in this section. @@ -177,10 +177,10 @@ For instance, to only show the menu item linked if it's the current one: * `$LinkOrSection`: Determines if the item is in the current section, so in the path towards the current page. Useful for menus which you only want to show a second level menu when you are on that page or a child of it. Returns "link" or "section" strings. - * `InSection(page-url)`: This if block will pass if we're currently on the page-url page or one of its children. + * `$InSection(page-url)`: This if block will pass if we're currently on the page-url page or one of its children. :::ss - <% if InSection(about-us) %> + <% if $InSection(about-us) %>

You are viewing the about us section

<% end_if %> @@ -239,7 +239,7 @@ pages underneath a "staff" holder on any page, regardless if its on the top leve ### AllChildren Content authors have the ability to hide pages from menus by un-selecting the `ShowInMenus` checkbox within the CMS. -This option will be honored by `<% loop Children %>` and `<% loop Menu %>` however if you want to ignore the user +This option will be honored by `<% loop $Children %>` and `<% loop $Menu %>` however if you want to ignore the user preference, `AllChildren` does not filter by `ShowInMenus`. :::ss @@ -364,7 +364,7 @@ page. The previous example could be rewritten to use the following syntax. Breadcrumbs are the path of pages which need to be taken to reach the current page, and can be a great navigation aid for website users. -While you can achieve breadcrumbs through the `<% Level() %>` control manually, there's a nicer shortcut: The +While you can achieve breadcrumbs through the `$Level()` control manually, there's a nicer shortcut: The `$Breadcrumbs` variable. :::ss @@ -380,7 +380,7 @@ By default, it uses the template defined in `cms/templates/BreadcrumbsTemplate.s <% end_if %>
-To customize the markup that the `$Breadcrumbs` generates. Copy `cms/templates/BreadcrumbsTemplate.ss` to +To customize the markup that the `$Breadcrumbs` generates, copy `cms/templates/BreadcrumbsTemplate.ss` to `mysite/templates/BreadcrumbsTemplate.ss`, modify the newly copied template and flush your SilverStripe cache.
diff --git a/docs/en/02_Developer_Guides/01_Templates/03_Requirements.md b/docs/en/02_Developer_Guides/01_Templates/03_Requirements.md index 33198213f..1dd70c401 100644 --- a/docs/en/02_Developer_Guides/01_Templates/03_Requirements.md +++ b/docs/en/02_Developer_Guides/01_Templates/03_Requirements.md @@ -64,6 +64,8 @@ JavaScript in a separate file and instead load, via search and replace, several Requirements::javascriptTemplate("cms/javascript/editor.template.js", $vars); +In this example, `editor.template.js` is expected to contain a replaceable variable expressed as `$EditorCSS`. + ### Custom Inline CSS or Javascript You can also quote custom script directly. This may seem a bit ugly, but is useful when you need to transfer some kind @@ -103,7 +105,7 @@ To make debugging easier in your local environment, combined files is disabled w mode. -By default it stores the generated file in the assets/ folder but you can configure this by pointing the +By default it stores the generated file in the assets/ folder, but you can configure this by pointing the `Requirements.combined_files_folder` configuration setting to a specific folder. **mysite/_config/app.yml** @@ -136,7 +138,7 @@ the third paramter of the `combine_files` function: Clears all defined requirements. You can also clear specific requirements. :::php - Requirements::clear('jsparty/prototype.js'); + Requirements::clear(THIRDPARTY_DIR.'/prototype.js');
Depending on where you call this command, a Requirement might be *re-included* afterwards.