mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Using new template controls in docs
This commit is contained in:
parent
868d3697fd
commit
45b2cbfddd
@ -130,9 +130,9 @@ and replace it with the following:
|
||||
|
||||
:::ss
|
||||
<ul>
|
||||
<% control BookmarkedPages %>
|
||||
<% loop BookmarkedPages %>
|
||||
<li><a href="admin/page/edit/show/$ID">Edit "$Title"</a></li>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
</ul>
|
||||
|
||||
## Summary
|
||||
|
@ -74,14 +74,14 @@ In this case, the `getTitleFirstLetter()` method defined earlier is used to brea
|
||||
:::ss
|
||||
<%-- Modules list grouped by TitleFirstLetter --%>
|
||||
<h2>Modules</h2>
|
||||
<% control GroupedModules.GroupedBy(TitleFirstLetter) %>
|
||||
<% loop GroupedModules.GroupedBy(TitleFirstLetter) %>
|
||||
<h3>$TitleFirstLetter</h3>
|
||||
<ul>
|
||||
<% control Children %>
|
||||
<% loop Children %>
|
||||
<li>$Title</li>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
</ul>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
|
||||
## Grouping Sets By Month
|
||||
|
||||
@ -133,14 +133,14 @@ The final step is the render this into the template using the [api:GroupedList->
|
||||
:::ss
|
||||
// Modules list grouped by the Month Posted
|
||||
<h2>Modules</h2>
|
||||
<% control GroupedModulesByDate.GroupedBy(MonthCreated) %>
|
||||
<% loop GroupedModulesByDate.GroupedBy(MonthCreated) %>
|
||||
<h3>$MonthCreated</h3>
|
||||
<ul>
|
||||
<% control Children %>
|
||||
<% loop Children %>
|
||||
<li>$Title ($Created.Nice)</li>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
</ul>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
|
||||
## Related
|
||||
|
||||
|
@ -32,9 +32,9 @@ The first step is to simply list the objects in the template:
|
||||
|
||||
:::ss
|
||||
<ul>
|
||||
<% control PaginatedPages %>
|
||||
<% loop PaginatedPages %>
|
||||
<li><a href="$Link">$Title</a></li>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
</ul>
|
||||
|
||||
By default this will display 10 pages at a time. The next step is to add pagination
|
||||
@ -45,7 +45,7 @@ controls below this so the user can switch between pages:
|
||||
<% if PaginatedPages.NotFirstPage %>
|
||||
<a class="prev" href="$PaginatedPages.PrevLink">Prev</a>
|
||||
<% end_if %>
|
||||
<% control PaginatedPages.Pages %>
|
||||
<% loop PaginatedPages.Pages %>
|
||||
<% if CurrentBool %>
|
||||
$PageNum
|
||||
<% else %>
|
||||
@ -55,7 +55,7 @@ controls below this so the user can switch between pages:
|
||||
...
|
||||
<% end_if %>
|
||||
<% end_if %>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
<% if PaginatedPages.NotLastPage %>
|
||||
<a class="next" href="$PaginatedPages.NextLink">Next</a>
|
||||
<% end_if %>
|
||||
|
@ -420,7 +420,7 @@ Put code into the classes in the following order (where applicable).
|
||||
* Commonly used methods like `getCMSFields()`
|
||||
* Accessor methods (`getMyField()` and `setMyField()`)
|
||||
* Controller action methods
|
||||
* Template data-access methods (methods that will be called by a `$MethodName` or `<% control MethodName %>` construct in a template somewhere)
|
||||
* Template data-access methods (methods that will be called by a `$MethodName` or `<% loop MethodName %>` construct in a template somewhere)
|
||||
* Object methods
|
||||
|
||||
### SQL Format
|
||||
|
@ -23,7 +23,7 @@ The way you mark a section of the template as being cached is to wrap that secti
|
||||
|
||||
|
||||
Each cache block has a cache key - an unlimited number of comma separated variables (in the same form as `if` and
|
||||
`control` tag variables) and quoted strings.
|
||||
`loop`/`with` tag variables) and quoted strings.
|
||||
|
||||
Every time the cache key returns a different result, the contents of the block are recalculated. If the cache key is the
|
||||
same as a previous render, the cached value stored last time is used.
|
||||
@ -207,7 +207,7 @@ could also write the last example as:
|
||||
|
||||
## The important rule
|
||||
|
||||
Currently cached blocks can not be contained within if or control blocks. The template engine will throw an error
|
||||
Currently cached blocks can not be contained within if or loop blocks. The template engine will throw an error
|
||||
letting you know if you've done this. You can often get around this using aggregates.
|
||||
|
||||
Failing example:
|
||||
@ -215,11 +215,11 @@ Failing example:
|
||||
:::ss
|
||||
<% cached LastEdited %>
|
||||
|
||||
<% control Children %>
|
||||
<% loop Children %>
|
||||
<% cached LastEdited %>
|
||||
$Name
|
||||
<% end_cached %>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
|
||||
<% end_cached %>
|
||||
|
||||
@ -231,9 +231,9 @@ Can be re-written as:
|
||||
<% cached LastEdited %>
|
||||
|
||||
<% cached Children.max(LastEdited) %>
|
||||
<% control Children %>
|
||||
<% loop Children %>
|
||||
$Name
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
<% end_cached %>
|
||||
|
||||
<% end_cached %>
|
||||
|
@ -141,9 +141,9 @@ Results.PaginationSummary(4) defines how many pages the search will show in the
|
||||
:::ss
|
||||
<% if Results %>
|
||||
<ul>
|
||||
<% control Results %>
|
||||
<li>$Titulo, $Autor</li>
|
||||
<% end_control %>
|
||||
<% loop Results %>
|
||||
<li>$Title, $Autor</li>
|
||||
<% end_loop %>
|
||||
</ul>
|
||||
<% else %>
|
||||
<p>Sorry, your search query did not return any results.</p>
|
||||
@ -157,7 +157,7 @@ Results.PaginationSummary(4) defines how many pages the search will show in the
|
||||
<% end_if %>
|
||||
|
||||
<span>
|
||||
<% control Results.PaginationSummary(4) %>
|
||||
<% loop Results.PaginationSummary(4) %>
|
||||
<% if CurrentBool %>
|
||||
$PageNum
|
||||
<% else %>
|
||||
@ -167,7 +167,7 @@ Results.PaginationSummary(4) defines how many pages the search will show in the
|
||||
…
|
||||
<% end_if %>
|
||||
<% end_if %>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
</span>
|
||||
|
||||
<% if Results.NotLastPage %>
|
||||
|
@ -15,9 +15,9 @@ You can access `[api:SiteConfig]` options from any SS template by using the func
|
||||
|
||||
// or
|
||||
|
||||
<% control SiteConfig %>
|
||||
<% loop SiteConfig %>
|
||||
$Title $AnotherField
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
|
||||
|
||||
Or if you want to access variables in the PHP you can do
|
||||
|
@ -40,7 +40,7 @@ are `filter()` and `sort()`:
|
||||
|
||||
Those of you who know a bit about SQL might be thinking "it looks like you're querying all members, and then filtering
|
||||
to those with a first name of 'Sam'. Isn't this very slow?" Is isn't, because the ORM doesn't actually execute the
|
||||
query until you iterate on the result with a `foreach()` or `<% control %>`.
|
||||
query until you iterate on the result with a `foreach()` or `<% loop %>`.
|
||||
|
||||
:::php
|
||||
// The SQL query isn't executed here...
|
||||
@ -403,7 +403,7 @@ but using the *obj()*-method or accessing through a template will cast the value
|
||||
|
||||
// $myPlayer->MembershipFee() returns a float (e.g. 123.45)
|
||||
// $myPlayer->obj('MembershipFee') returns a object of type Currency
|
||||
// In a template: <% control MyPlayer %>MembershipFee.Nice<% end_control %> returns a casted string (e.g. "$123.45")
|
||||
// In a template: <% loop MyPlayer %>MembershipFee.Nice<% end_loop %> returns a casted string (e.g. "$123.45")
|
||||
public function getMembershipFee() {
|
||||
return $this->Team()->BaseFee * $this->MembershipYears;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ The default HTML template is located in `framework/templates/email/GenericEmail.
|
||||
### Templates
|
||||
|
||||
* Create a SS-template file called, in this example we will use 'MyEmail.ss' inside `mysite/templates/email`.
|
||||
* Fill this out with the body text for your email. You can use any [SS-template syntax](/topics/templates) (e.g. `<% control %>`,
|
||||
* Fill this out with the body text for your email. You can use any [SS-template syntax](/topics/templates) (e.g. `<% loop %>`,
|
||||
`<% if %>`, $FirstName etc)
|
||||
* Choose your template with **setTemplate()**
|
||||
* Populate any custom data into the template before sending with **populateTemplate()**
|
||||
|
@ -223,7 +223,7 @@ basic customisation:
|
||||
|
||||
<% if Actions %>
|
||||
<div class="Actions">
|
||||
<% control Actions %>$Field<% end_control %>
|
||||
<% loop Actions %>$Field<% end_loop %>
|
||||
</div>
|
||||
<% end_if %>
|
||||
</form>
|
||||
@ -234,7 +234,7 @@ for the type of field. Pass in the name of the field as the first parameter, as
|
||||
template.
|
||||
|
||||
To find more methods, have a look at the `[api:Form]` class, as there is a lot of different methods of customising the form
|
||||
templates, for example, you could use `<% control Fields %>` instead of specifying each field manually, as we've done
|
||||
templates, for example, you could use `<% loop Fields %>` instead of specifying each field manually, as we've done
|
||||
above.
|
||||
|
||||
### Custom form field templates
|
||||
|
@ -375,9 +375,9 @@ Template:
|
||||
|
||||
:::ss
|
||||
<ul>
|
||||
<% control Results %>
|
||||
<% loop Results %>
|
||||
<li id="Result-$ID">$Title</li>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
</ul>
|
||||
|
||||
|
||||
|
@ -121,10 +121,10 @@ of the CMS you have to take care of instanciation yourself:
|
||||
:::ss
|
||||
// File: mysite/templates/MyController.ss
|
||||
$Form
|
||||
<% control EditorToolbar %>
|
||||
<% with EditorToolbar %>
|
||||
$MediaForm
|
||||
$LinkForm
|
||||
<% end_control %>
|
||||
<% end_with %>
|
||||
|
||||
Note: The dialogs rely on CMS-access, e.g. for uploading and browsing files,
|
||||
so this is considered advanced usage of the field.
|
||||
|
@ -74,9 +74,9 @@ our theme in action. The code for mine is below.
|
||||
<div id="Navigation">
|
||||
<% if Menu(1) %>
|
||||
<ul>
|
||||
<% control Menu(1) %>
|
||||
<% loop Menu(1) %>
|
||||
<li><a href="$Link" title="Go to the $Title page" class="$LinkingMode">$MenuTitle</a></li>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
</ul>
|
||||
<% end_if %>
|
||||
</div>
|
||||
@ -183,9 +183,9 @@ Next is a division for the main navigation. This may contain something like:
|
||||
<div id="Navigation">
|
||||
<% if Menu(1) %>
|
||||
<ul>
|
||||
<% control Menu(1) %>
|
||||
<% loop Menu(1) %>
|
||||
<li><a href="$Link" title="Go to the $Title page" class="$LinkingMode">$MenuTitle</a></li>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
</ul>
|
||||
<% end_if %>
|
||||
</div>
|
||||
@ -193,14 +193,14 @@ Next is a division for the main navigation. This may contain something like:
|
||||
|
||||
This is the standard for creating the main Navigation. As you can see it outputs the Menu 1 in a unordered list.
|
||||
|
||||
Before stepping into a control (a foreach loop) it's good practise to check if it exists first. This is not only
|
||||
Before stepping into a loop it's good practise to check if it exists first. This is not only
|
||||
important in manipulating SilverStripe templates, but in any programming language!
|
||||
|
||||
:::ss
|
||||
<% if MyFunction %>
|
||||
<% control MyFunction %>
|
||||
<% loop MyFunction %>
|
||||
$Title
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
<% end_if %>
|
||||
|
||||
|
||||
|
@ -388,12 +388,12 @@ The final step is to create the template to display our data. Change the 'Browse
|
||||
$BrowserPollForm
|
||||
<% else %>
|
||||
<ul>
|
||||
<% control BrowserPollResults %>
|
||||
<% loop BrowserPollResults %>
|
||||
<li>
|
||||
<div class="browser">$Browser: $Percentage%</div>
|
||||
<div class="bar" style="width:$Percentage%"> </div>
|
||||
</li>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
</ul>
|
||||
<% end_if %>
|
||||
</div>
|
||||
|
@ -113,7 +113,7 @@ class.
|
||||
|
||||
<% if Results %>
|
||||
<ul id="SearchResults">
|
||||
<% control Results %>
|
||||
<% loop Results %>
|
||||
<li>
|
||||
<a class="searchResultHeader" href="$Link">
|
||||
<% if MenuTitle %>
|
||||
@ -127,7 +127,7 @@ class.
|
||||
title="Read more about "{$Title}""
|
||||
>Read more about "{$Title}"...</a>
|
||||
</li>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
</ul>
|
||||
<% else %>
|
||||
<p>Sorry, your search query did not return any results.</p>
|
||||
@ -142,13 +142,13 @@ class.
|
||||
<a class="prev" href="$Results.PrevLink" title="View the previous page">Prev</a>
|
||||
<% end_if %>
|
||||
<span>
|
||||
<% control Results.Pages %>
|
||||
<% loop Results.Pages %>
|
||||
<% if CurrentBool %>
|
||||
$PageNum
|
||||
<% else %>
|
||||
<a href="$Link" title="View page number $PageNum">$PageNum</a>
|
||||
<% end_if %>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
</span>
|
||||
<p>Page $Results.CurrentPage of $Results.TotalPages</p>
|
||||
</div>
|
||||
|
@ -505,44 +505,44 @@ Let's start with the *ProjectsHolder* page created before. For this template, we
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% control Children %>
|
||||
<% loop Children %>
|
||||
<tr>
|
||||
<td>$Title</td>
|
||||
<td>
|
||||
<% if MyStudent %>
|
||||
<% control MyStudent %>
|
||||
<% loop MyStudent %>
|
||||
$FirstName $Lastname
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
<% else %>
|
||||
No Student
|
||||
<% end_if %>
|
||||
</td>
|
||||
<td>
|
||||
<% if MyStudent %>
|
||||
<% control MyStudent %>
|
||||
<% loop MyStudent %>
|
||||
<% if MyMentor %>
|
||||
<% control MyMentor %>
|
||||
<% loop MyMentor %>
|
||||
$FirstName $Lastname
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
<% else %>
|
||||
No Mentor
|
||||
<% end_if %>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
<% else %>
|
||||
No Mentor
|
||||
<% end_if %>
|
||||
</td>
|
||||
<td>
|
||||
<% if Modules %>
|
||||
<% control Modules %>
|
||||
<% loop Modules %>
|
||||
$Name
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
<% else %>
|
||||
No Modules
|
||||
<% end_if %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@ -579,7 +579,7 @@ We can now do the same for every *Project* page by creating its own template.
|
||||
$Content
|
||||
|
||||
<% if MyStudent %>
|
||||
<% control MyStudent %>
|
||||
<% loop MyStudent %>
|
||||
<p>First Name: <strong>$FirstName</strong></p>
|
||||
<p>Lastname: <strong>$Lastname</strong></p>
|
||||
<p>Nationality: <strong>$Nationality</strong></p>
|
||||
@ -587,15 +587,15 @@ We can now do the same for every *Project* page by creating its own template.
|
||||
<h3>Mentor</h3>
|
||||
|
||||
<% if MyMentor %>
|
||||
<% control MyMentor %>
|
||||
<% loop MyMentor %>
|
||||
<p>First Name: <strong>$FirstName</strong></p>
|
||||
<p>Lastname: <strong>$Lastname</strong></p>
|
||||
<p>Nationality: <strong>$Nationality</strong></p>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
<% else %>
|
||||
<p>This student doesn't have any mentor.</p>
|
||||
<% end_if %>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
<% else %>
|
||||
<p>There is no any student working on this project.</p>
|
||||
<% end_if %>
|
||||
@ -604,9 +604,9 @@ We can now do the same for every *Project* page by creating its own template.
|
||||
|
||||
<% if Modules %>
|
||||
<ul>
|
||||
<% control Modules %>
|
||||
<% loop Modules %>
|
||||
<li>$Name</li>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
</ul>
|
||||
<% else %>
|
||||
<p>This project has not used any modules.</p>
|
||||
@ -655,13 +655,13 @@ We can now modify the *Project.ss* template.
|
||||
|
||||
<h3>Mentor</h3>
|
||||
|
||||
<% control MyStudent %>
|
||||
<% loop MyStudent %>
|
||||
<% if MyMentor %>
|
||||
$MyMentor.PersonalInfo
|
||||
<% else %>
|
||||
<p>This student doesn't have any mentor.</p>
|
||||
<% end_if %>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
<% else %>
|
||||
<p>There is no any student working on this project.</p>
|
||||
<% end_if %>
|
||||
@ -738,20 +738,20 @@ That's how we can use this function in the *Mentor* template.
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% control Students %>
|
||||
<% loop Students %>
|
||||
<tr>
|
||||
<td>$FirstName $Lastname</td>
|
||||
<td>
|
||||
<% if MyProject %>
|
||||
<% control MyProject %>
|
||||
<% loop MyProject %>
|
||||
$Title
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
<% else %>
|
||||
No Project
|
||||
<% end_if %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
|
Loading…
Reference in New Issue
Block a user