added Umbraco.Web.UI containing only web rendering files

This commit is contained in:
shannon@ShandemVaio
2012-07-18 04:35:30 +06:00
parent 8046a778bd
commit 62f4db0b76
1363 changed files with 101455 additions and 2 deletions

View File

@@ -0,0 +1,21 @@
@*
BREADCRUMB
=================================
This snippet makes a breadcrumb of parents using an unordred html list.
How it works:
- It uses the Ancestors() method to get all parents and then generates links so the visitor get go back
- Finally it outputs the name of the current page (without a link)
NOTE: It is safe to remove this comment (anything between @ * * @), the code that generates the list is only the below!
*@
@inherits umbraco.MacroEngines.DynamicNodeContext
<ul>
@foreach(var level in @Model.Ancestors().Where("Visible"))
{
<li><a href="@level.Url">@level.Name</a></li>
}
<li>@Model.Name</li>
</ul>

View File

@@ -0,0 +1,22 @@
@*
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
@{ var numberOfItems = 10; }
<ul>
@foreach (var item in @Model.Children.Where("Visible").OrderBy("UpdateDate").Take(numberOfItems))
{
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>

View File

@@ -0,0 +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>

View File

@@ -0,0 +1,34 @@
@*
USING MEDIA
=================================
This snippet shows two ways of working with referenced media. Media is referenced from a page using a property with
the type of 'MediaPicker' (or similar for instance MultiNodePicker in uComponents).
How it works:
- First we check that there's a property on the current page called 'relatedMedia' and that it has a selected value
- In the first example we simply needs the path of the media which is stored in the property 'umbracoFile' and the
media is referenced in the property with the alias of 'relatedMedia'. One line is all it takes!
- In the second example we store the referenced media in a variable as we'd like to get not just the path but also
the name of the media for the friendly alt attribute.
NOTE: It is safe to remove this comment (anything between @ * * @), the code that generates the list is only the below!
*@
@inherits umbraco.MacroEngines.DynamicNodeContext
@if (Model.HasProperty("relatedMedia") && Model.RelatedMedia != 0) {
<p>Simple: <br />
<img src='@Model.Media("relatedMedia", "umbracoFile")' />
</p>
<p>Advanced: <br />
@{
var image = @Model.Media("relatedMedia");
}
<img src='@image.UmbracoFile' alt='@image.Name' />
</p>
} else {
<p>
This page doesn't contain a MediaPicker property with the alias of 'RelatedMedia'
or No image is selected on this page
</p>
}

View File

@@ -0,0 +1,36 @@
@*
NAVIGATION BY LEVEL
=================================
This snippet makes it easy to do navigation based lists! It'll automatically list all children of a page with a certain
level in the hierarchy that's published and visible (it'll filter out any pages with a property named "umbracoNaviHide"
that's set to 'true'.
How to Customize for re-use (only applies to Macros, not if you insert this snippet directly in a template):
- If you add a Macro Parameter with the alias of "Level" you can use this macro for both level 1 and level 2 navigations
- If you add a Macro Parameter with the alias of "ulClass" you can specify different css classes for the <UL/> element
How it works:
- The first two lines (var level... and var ulClass) assigns default values if none is specified via Macro Parameters
- Then it finds the correct parent based on the level and assigns it to the 'parent' variable.
- Then it runs through all the visible children in the foreach loop and outputs a list item
- Inside the list item it checks if the page added to the list is a parent of the current page. Then it marks it 'selected'
NOTE: It is safe to remove this comment (anything between @ * * @), the code that generates the list is only the below!
*@
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var level = String.IsNullOrEmpty(Parameter.Level) ? 1 : int.Parse(Parameter.Level);
var ulClass = String.IsNullOrEmpty(Parameter.UlClass) ? "" : String.Format(" class=\"{0}\"", Parameter.UlClass);
var parent = @Model.AncestorOrSelf(level);
if (parent != null) {
<ul@Html.Raw(ulClass)>
@foreach (var item in parent.Children.Where("Visible")) {
var selected = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"selected\"" : "";
<li@Html.Raw(selected)>
<a href="@item.Url">@item.Name</a>
</li>
}
</ul>
}
}

View File

@@ -0,0 +1,83 @@
@*
HOW TO DO PAGING
=================================
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 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:
- 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!
*@
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var pagesToList = @Model.Children;
// configuration
var itemsPerPage = String.IsNullOrEmpty(Parameter.ItemsPerPage) ? 3 : int.Parse(Parameter.ItemsPerPage);
var previousLabel = String.IsNullOrEmpty(Parameter.PreviousLabel) ? "Previous" : Parameter.PreviousLabel;
var nextLabel = String.IsNullOrEmpty(Parameter.NextLabel) ? "Next" : Parameter.NextLabel;
// paging calculations
var numberOfItems = pagesToList.Count();
int currentPage = 1;
if (!int.TryParse(HttpContext.Current.Request.QueryString["Page"], out currentPage)) {
currentPage = 1;
}
currentPage--;
var numberOfPages = numberOfItems % itemsPerPage == 0 ? Math.Ceiling((decimal)(numberOfItems / itemsPerPage)) : Math.Ceiling((decimal)(numberOfItems / itemsPerPage))+1;
<p>
Total Items: @numberOfItems <br />
Items per Page: @itemsPerPage<br />
Pages: @numberOfPages;<br />
Current Page: @(currentPage)
</p>
<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)">&laquo; @previousLabel</a>
} else {
<span class="pagingDisabled">&laquo; @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("&nbsp&nbsp");
}
if (currentPage < Pages.Count()-1) {
<a href="?page=@(currentPage+2)">@nextLabel &raquo;</a>
} else {
<span class="pagingDisabled">@nextLabel &raquo;</span>
}
}
</p>
}

View File

@@ -0,0 +1,16 @@
@*
LIST CHILDREN BY TYPE
=================================
This snippet shows how simple it is to fetch only children of a certain Document Type using Razor. Instead of
calling .Children, simply call .AliasOfDocumentType (even works in plural for readability)!
For instance .Textpage or .Textpages (you can find the alias of your Document Type by editing it in the
Settings section).
NOTE: It is safe to remove this comment (anything between @ * * @), the code that generates the list is only the below!
*@
<ul>
@foreach (var item in @Model.Textpages.Where("Visible"))
{
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>

View File

@@ -0,0 +1,44 @@
@*
SITEMAP
=================================
This snippet generates a complete sitemap of all pages that are published and visible (it'll filter out any
pages with a property named "umbracoNaviHide" that's set to 'true'). It's also a great example on how to make
helper methods in Razor and how to pass values to your '.Where' filters.
How to Customize for re-use (only applies to Macros, not if you insert this snippet directly in a template):
- If you add a Macro Parameter with the alias of "MaxLevelForSitemap" which specifies how deep in the hierarchy to traverse
How it works:
- The first line (var maxLevelForSitemap) assigns default values if none is specified via Macro Parameters
- Next is a helper method 'traverse' which uses recursion to keep making new lists for each level in the sitemap
- Inside the the 'traverse' method there's an example of using a 'Dictionary' to pass the 'maxLevelForSitemap' to
the .Where filter
- Finally the 'traverse' method is called taking the very top node of the website by calling AncesterOrSelf()
NOTE: It is safe to remove this comment (anything between @ * * @), the code that generates the list is only the below!
*@
@inherits umbraco.MacroEngines.DynamicNodeContext
@helper traverse(dynamic node){
var maxLevelForSitemap = String.IsNullOrEmpty(Parameter.MaxLevelForSitemap) ? 4 : int.Parse(Parameter.MaxLevelForSitemap);
var values = new Dictionary<string,object>();
values.Add("maxLevelForSitemap", maxLevelForSitemap) ;
var items = node.Children.Where("Visible").Where("Level <= maxLevelForSitemap", values);
if (items.Count() > 0) {
<ul>
@foreach (var item in items) {
<li>
<a href="@item.Url">@item.Name</a>
@traverse(item)
</li>
}
</ul>
}
}
<div class="sitemap">
@traverse(@Model.AncestorOrSelf())
</div>

View File

@@ -0,0 +1,37 @@
@*
USING RELATED LINKS (AND OTHER XML BASED TYPES
==============================================
This snippet shows how to work with properties that stores multiple values in XML such as the "Related Links" data type.
When the Razor (or in fact the 'DynamicNode') detected XML, it automatically makes it possible to navigate the xml by
using the name of the XML elements as properties. Be aware that the first xml element (the container) is always skipped
and that the properties are case sensitive!
How it works:
- First we check if there's a property on the current page (Model) named 'relatedLinks'
- Then we loop through the XML elements of the property 'RelatedLinks' (ie. all the links)
- For each link we check if it should be opened in a new window (stored in an XML attribute called 'newwindow' which is
automatically translated into a property '.newwindow' by DynamicNode
- Then we test if the link type is a internal or external link, and if it's an internal link we use the NiceUrl helper
method to convert the id of the page to a SEO friendly url
NOTE: It is safe to remove this comment (anything between @ * * @), the code that generates the list is only the below!
*@
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
if (Model.HasProperty("relatedLinks")) {
<ul>
@foreach (var link in @Model.RelatedLinks) {
string target = link.newwindow == "1" ? " target=\"_blank\"" : "";
<li>
@if (link.type == "internal") {
<a href="@umbraco.library.NiceUrl(int.Parse(link.link))"@Html.Raw(target)>@link.title</a>
} else {
<a href="@link.link"@Html.Raw(target)>@link.title</a>
}
</li>
}
</ul>
}
}

View File

@@ -0,0 +1,17 @@
from umbraco.presentation.nodeFactory import Node
from umbraco import library
#set the node id you would like to fetch pages from here
#you can also set it as a macro property with the alias 'nodeId' instead
rootNodeId = int(nodeId)
result = "<ul>"
for childNode in Node(rootNodeId).Children:
result += "<li><a href='" + library.NiceUrl(childNode.Id) + "'>" + childNode.Name + "</a></li>"
result += "</ul>"
print result

View File

@@ -0,0 +1,15 @@
from umbraco.presentation.nodeFactory import Node
from umbraco import library
#set the node id you would like to fetch pages from here
#you can also set it as a macro property with the alias 'nodeId' instead
result = "<ul>"
for childNode in currentPage.Children:
result += "<li><a href='" + library.NiceUrl(childNode.Id) + "'>" + childNode.Name + "</a></li>"
result += "</ul>"
print result

View File

@@ -0,0 +1,20 @@
Umbraco = Object.const_get("umbraco")
Library = Umbraco.const_get("library")
NodeFactory = Umbraco.const_get("presentation").const_get("nodeFactory")
# Set the node id you would like to fetch pages from here
# You can also set it as a macro property with the alias 'nodeId' instead
parent = NodeFactory::Node.new(System::Int32.Parse(nodeId))
# Start writing out the list
result = "<ul>"
parent.Children.each do |child|
result += "<li><a href='" + Library.NiceUrl(child.Id) + "'>" + child.Name + "</a></li>"
end
result += "</ul>"
puts result

View File

@@ -0,0 +1,9 @@
result = "<ul>";
currentPage.Children.each do |this_item|
result += "<li><a href='" + this_item.NiceUrl + "'>" + this_item.Name + "</a></li>"
end
result += "</ul>"
puts result