mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
developer guides, templates review
This commit is contained in:
parent
71cbcd4920
commit
59dcd4d181
@ -42,7 +42,7 @@ An example of a SilverStripe template is below:
|
||||
|
||||
<div class="note">
|
||||
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.
|
||||
</div>
|
||||
|
||||
## Variables
|
||||
@ -92,6 +92,10 @@ Variables can come from your database fields, or custom methods you define on yo
|
||||
:::html
|
||||
<p>You are coming from $UsersIpAddress.</p>
|
||||
|
||||
<div class="node" markdown="1">
|
||||
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()`.
|
||||
</div>
|
||||
|
||||
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
|
||||
<p>You are logged in as $CurrentMember.FirstName $CurrentMember.Surname.</p>
|
||||
<% 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`.
|
||||
|
||||
<div class="info" markdown="1">
|
||||
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.
|
||||
</div>
|
||||
|
||||
|
||||
## Comments
|
||||
|
@ -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) %>
|
||||
<p>You are viewing the about us section</p>
|
||||
<% 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(<level>) %>` control manually, there's a nicer shortcut: The
|
||||
While you can achieve breadcrumbs through the `$Level(<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 %>
|
||||
|
||||
<div class="info" markdown="1">
|
||||
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.
|
||||
</div>
|
||||
|
||||
|
@ -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.
|
||||
</div>
|
||||
|
||||
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');
|
||||
|
||||
<div class="alert" markdown="1">
|
||||
Depending on where you call this command, a Requirement might be *re-included* afterwards.
|
||||
|
Loading…
Reference in New Issue
Block a user