Added documentation to all Razor templates
This commit is contained in:
@@ -1,3 +1,16 @@
|
|||||||
|
@*
|
||||||
|
LIST SUBPAGES BY LIMIT AND DATETIME
|
||||||
|
===================================
|
||||||
|
This snippet shows how easy it is to combine different queries. It lists the children of the currentpage which is
|
||||||
|
visible and then grabs a specified number of items sorted by the day they're updated.
|
||||||
|
|
||||||
|
How it works:
|
||||||
|
- It uses the Take() method to specify a maximum number of items to output
|
||||||
|
- It adds a OrderBy() to sort the items. You can even combine this, for instance OrderBy("UpdateDate, Name desc")
|
||||||
|
|
||||||
|
NOTE: It is safe to remove this comment (anything between @ * * @), the code that generates the list is only the below!
|
||||||
|
*@
|
||||||
|
|
||||||
@inherits umbraco.MacroEngines.DynamicNodeContext
|
@inherits umbraco.MacroEngines.DynamicNodeContext
|
||||||
|
|
||||||
@{ var numberOfItems = 10; }
|
@{ var numberOfItems = 10; }
|
||||||
|
|||||||
@@ -1,2 +1,16 @@
|
|||||||
|
@*
|
||||||
|
MACRO PARAMETERS
|
||||||
|
===================================
|
||||||
|
This snippet is a very simple example on how to grab values specified via Macro Parameters. Macro Parameters are
|
||||||
|
'attributes' that can be added to Macros (doesn't make sense when Razor is used inline) that makes it possible to
|
||||||
|
re-use macros for multiple purposes. When you add a Macro Parameter to a Macro, the user can send different values
|
||||||
|
to the Macro when it's inserted. Macro Parameters in Razor can be accessed via the Parameter property.
|
||||||
|
|
||||||
|
How it works:
|
||||||
|
- In this example it'll output the value specified in a Macro Parameter with the alias 'Who'.
|
||||||
|
|
||||||
|
NOTE: It is safe to remove this comment (anything between @ * * @), the code that generates the list is only the below!
|
||||||
|
*@
|
||||||
|
|
||||||
|
|
||||||
<h3>Hello @Parameter.Who</h3>
|
<h3>Hello @Parameter.Who</h3>
|
||||||
@@ -20,17 +20,17 @@ NOTE: It is safe to remove this comment (anything between @ * * @), the code tha
|
|||||||
|
|
||||||
@inherits umbraco.MacroEngines.DynamicNodeContext
|
@inherits umbraco.MacroEngines.DynamicNodeContext
|
||||||
@{
|
@{
|
||||||
var level = String.IsNullOrEmpty(Parameter.Level) ? 1 : int.Parse(Parameter.Level);
|
var level = String.IsNullOrEmpty(Parameter.Level) ? 1 : int.Parse(Parameter.Level);
|
||||||
var ulClass = String.IsNullOrEmpty(Parameter.UlClass) ? "" : String.Format(" class=\"{0}\"", Parameter.UlClass);
|
var ulClass = String.IsNullOrEmpty(Parameter.UlClass) ? "" : String.Format(" class=\"{0}\"", Parameter.UlClass);
|
||||||
var parent = @Model.AncestorOrSelf(level);
|
var parent = @Model.AncestorOrSelf(level);
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
<ul@Html.Raw(ulClass)>
|
<ul@Html.Raw(ulClass)>
|
||||||
@foreach (var item in parent.Children.Where("Visible")) {
|
@foreach (var item in parent.Children.Where("Visible")) {
|
||||||
var selected = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"selected\"" : "";
|
var selected = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"selected\"" : "";
|
||||||
<li@Html.Raw(selected)>
|
<li@Html.Raw(selected)>
|
||||||
<a href="@item.Url">@item.Name (@item.Id)</a>
|
<a href="@item.Url">@item.Name</a>
|
||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,51 +1,83 @@
|
|||||||
@*
|
@*
|
||||||
HOW TO DO PAGING
|
HOW TO DO PAGING
|
||||||
=================================
|
=================================
|
||||||
Intro
|
This an example of how to do paging of content including a Google style page navigation. You likely want to
|
||||||
|
modify the query (first line, assigned to the 'pagesToList' variable) and the output made within the foreach
|
||||||
|
loop (<li> ... </li>)
|
||||||
|
|
||||||
How to customize:
|
How to Customize for re-use (only applies to Macros, not if you insert this snippet directly in a template):
|
||||||
-
|
- You can customize the number of items per page by adding a Macro Parameter with the alias of "ItemsPerPage"
|
||||||
|
- You can customize the labels of previous/next by adding Macro Parameters with the alias of "PreviousLabel" and
|
||||||
|
"NextLabel"
|
||||||
|
|
||||||
How it works:
|
How it works:
|
||||||
-
|
- The pages to display is added to the variable 'pagesToList'. To change what pages to list, simply update the query
|
||||||
|
- The next part assigns the number of items and the previous/next labels using either default values or Macro Parameters
|
||||||
|
- Then it's using a bit of math to calculate how many pages and what should currently be displayed
|
||||||
|
- In the first <p /> element, a summary is printed. This could likely be removed
|
||||||
|
- In the <ul /> the magic happens. Notice how it's using Skip() and Take() to jump to the relevant items and iterate
|
||||||
|
over the number of items to display
|
||||||
|
- In the end it added a Google style page navigation (<<Previous 1 2 3 4 Next >>)
|
||||||
|
|
||||||
NOTE: It is safe to remove this comment (anything between @ * * @), the code that generates the list is only the below!
|
NOTE: It is safe to remove this comment (anything between @ * * @), the code that generates the list is only the below!
|
||||||
*@
|
*@
|
||||||
|
|
||||||
@inherits umbraco.MacroEngines.DynamicNodeContext
|
@inherits umbraco.MacroEngines.DynamicNodeContext
|
||||||
@{
|
@{
|
||||||
var pagesToList = @Model.Children;
|
var pagesToList = @Model.Children;
|
||||||
var itemsPerPage = 3;
|
|
||||||
var numberOfItems = pagesToList.Count();
|
|
||||||
int currentPage = 1;
|
|
||||||
if (!int.TryParse(HttpContext.Current.Request.QueryString["Page"], out currentPage)) {
|
|
||||||
currentPage = 1;
|
|
||||||
}
|
|
||||||
currentPage--;
|
|
||||||
// THERE'S A BUG IN THIS COUNTER!
|
|
||||||
var numberOfPages = Math.Ceiling((decimal)(@numberOfItems / @itemsPerPage));
|
|
||||||
|
|
||||||
<p>
|
// configuration
|
||||||
Total Items: @numberOfItems <br />
|
var itemsPerPage = String.IsNullOrEmpty(Parameter.ItemsPerPage) ? 3 : int.Parse(Parameter.ItemsPerPage);
|
||||||
Items per Page: @itemsPerPage<br />
|
var previousLabel = String.IsNullOrEmpty(Parameter.PreviousLabel) ? "Previous" : Parameter.PreviousLabel;
|
||||||
Pages: @numberOfPages;<br />
|
var nextLabel = String.IsNullOrEmpty(Parameter.NextLabel) ? "Next" : Parameter.NextLabel;
|
||||||
Current Page: @(currentPage)
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<ul>
|
// paging calculations
|
||||||
@foreach(var item in pagesToList.Skip(currentPage*itemsPerPage).Take(itemsPerPage))
|
var numberOfItems = pagesToList.Count();
|
||||||
{
|
int currentPage = 1;
|
||||||
<li>@item.Name</li>
|
if (!int.TryParse(HttpContext.Current.Request.QueryString["Page"], out currentPage)) {
|
||||||
}
|
currentPage = 1;
|
||||||
</ul>
|
}
|
||||||
|
currentPage--;
|
||||||
|
var numberOfPages = numberOfItems % itemsPerPage == 0 ? Math.Ceiling((decimal)(numberOfItems / itemsPerPage)) : Math.Ceiling((decimal)(numberOfItems / itemsPerPage))+1;
|
||||||
|
|
||||||
var Pages = Enumerable.Range(1, (int)numberOfPages);
|
<p>
|
||||||
foreach(var number in Pages) {
|
Total Items: @numberOfItems <br />
|
||||||
if (number-1 != currentPage) {
|
Items per Page: @itemsPerPage<br />
|
||||||
<a href="?page=@number">@number</a>
|
Pages: @numberOfPages;<br />
|
||||||
} else {
|
Current Page: @(currentPage)
|
||||||
@number
|
</p>
|
||||||
}
|
|
||||||
@Html.Raw("  ");
|
<ul>
|
||||||
}
|
@foreach(var item in pagesToList.Skip(currentPage*itemsPerPage).Take(itemsPerPage))
|
||||||
}
|
{
|
||||||
|
<li>@item.Name</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p class="pagingPages">
|
||||||
|
@{
|
||||||
|
// Google style paging links
|
||||||
|
if (currentPage > 0) {
|
||||||
|
<a href="?page=@(currentPage)">« @previousLabel</a>
|
||||||
|
} else {
|
||||||
|
<span class="pagingDisabled">« @previousLabel</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
var Pages = Enumerable.Range(1, (int)numberOfPages);
|
||||||
|
foreach(var number in Pages) {
|
||||||
|
if (number-1 != currentPage) {
|
||||||
|
<a href="?page=@number">@number</a>
|
||||||
|
} else {
|
||||||
|
@number
|
||||||
|
}
|
||||||
|
@Html.Raw("  ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentPage < Pages.Count()-1) {
|
||||||
|
<a href="?page=@(currentPage+2)">@nextLabel »</a>
|
||||||
|
} else {
|
||||||
|
<span class="pagingDisabled">@nextLabel »</span>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</p>
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user