Add files from Douglas Robar

This commit is contained in:
Chriztian Steinmeier
2017-05-05 23:20:37 +02:00
parent 85d10014c2
commit 1a29a3237d
14 changed files with 121 additions and 88 deletions

View File

@@ -7,7 +7,7 @@
- Finally it outputs the name of the current page (without a link)
*@
@{ var selection = CurrentPage.Ancestors(); }
@{ var selection = Model.Content.Ancestors(); }
@if (selection.Any())
{
@@ -19,6 +19,6 @@
}
@* Display the current page as the last item in the list *@
<li class="active">@CurrentPage.Name</li>
<li class="active">@Model.Content.Name</li>
</ul>
}

View File

@@ -13,38 +13,38 @@
Type: (note: you can use a Single Media Picker if that's more appropriate to your needs)
*@
@{ var mediaIds = Model.MacroParameters["mediaIds"]; }
@{ var mediaIds = Model.MacroParameters["mediaIds"] as string; }
@if (mediaIds != null)
{
<ul class="thumbnails">
@foreach (var mediaId in mediaIds.ToString().Split(','))
<div class="row">
@foreach (var mediaId in mediaIds.Split(','))
{
var media = Umbraco.Media(mediaId);
var media = Umbraco.TypedMedia(mediaId);
@* a single image *@
if (media.DocumentTypeAlias == "Image")
{
@Render(media);
@Render(media as Image);
}
@* a folder with images under it *@
if (media.Children("Image").Any())
if (media.Children<Image>().Any())
{
foreach (var image in media.Children("Image"))
foreach (var image in media.Children<Image>())
{
@Render(image);
}
}
}
</ul>
</div>
}
@helper Render(dynamic item)
@helper Render(Image item)
{
<li class="span2">
<a href="@item.umbracoFile.src" class="thumbnail">
<img src="@item.umbracoFile.src" alt="@item.Name" />
<div class="col-xs-6 col-md-3">
<a href="@item.Url" class="thumbnail">
<img src="@item.GetCropUrl(width:200, height:200)" alt="@item.Name" />
</a>
</li>
</div>
}

View File

@@ -7,18 +7,18 @@
- Finally it outputs the name of the current page (without a link)
*@
@{ var selection = CurrentPage.Ancestors(); }
@{ var selection = Model.Content.Ancestors(); }
@if (selection.Any())
{
<ul>
@* For each page in the ancestors collection which have been ordered by Level (so we start with the highest top node first) *@
@foreach (var item in selection.OrderBy("Level"))
@foreach (var item in selection.OrderBy(x => x.Level))
{
<li><a href="@item.Url">@item.Name</a> &raquo;</li>
}
@* Display the current page as the last item in the list *@
<li>@CurrentPage.Name</li>
<li>@Model.Content.Name</li>
</ul>
}

View File

@@ -13,20 +13,19 @@
*@
@{ var startNodeId = Model.MacroParameters["startNodeId"]; }
@if (startNodeId != null)
{
@* Get the starting page *@
var startNode = Umbraco.Content(startNodeId);
var selection = startNode.Children.Where("Visible");
var startNode = Umbraco.TypedContent(startNodeId);
var selection = startNode.Children.Where(x => x.IsVisible());
if (selection.Any())
{
<ul>
@foreach (var item in selection)
{
<li>
<a href="@item.Url">@item.Name</a>
</li>
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
}

View File

@@ -1,6 +1,14 @@
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{ var selection = CurrentPage.Children.Where("Visible"); }
@*
This snippet makes a list of links to the of children of the current page using an unordered html list.
How it works:
- It uses the Children method to get all child pages
- It then generates links so the visitor can go to each page
*@
@{ var selection = Model.Content.Children.Where(x => x.IsVisible()); }
@if (selection.Any())
{

View File

@@ -1,11 +1,22 @@
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{ var selection = CurrentPage.Children.Where("Visible").OrderBy("CreateDate desc"); }
@* OrderBy() takes the property to sort by and optionally order desc/asc *@
@*
This snippet makes a list of links to the of children of the current page using an unordered html list.
<ul>
@foreach (var item in selection)
{
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
How it works:
- It uses the Children method to get all child pages
- It then uses the OrderByDescending() method, which takes the property to sort. In this case the page's creation date.
- It then generates links so the visitor can go to each page
*@
@{ var selection = Model.Content.Children.Where(x => x.IsVisible()).OrderByDescending(x => x.CreateDate); }
@if (selection.Any())
{
<ul>
@foreach (var item in selection)
{
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
}

View File

@@ -1,11 +1,22 @@
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{ var selection = CurrentPage.Children.Where("Visible").OrderBy("Name"); }
@* OrderBy() takes the property to sort by *@
@*
This snippet makes a list of links to the of children of the current page using an unordered html list.
<ul>
@foreach (var item in selection)
{
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
How it works:
- It uses the Children method to get all child pages
- It then uses the OrderBy() method, which takes the property to sort. In this case, the page's name.
- It then generates links so the visitor can go to each page
*@
@{ var selection = Model.Content.Children.Where(x => x.IsVisible()).OrderBy(x => x.Name); }
@if (selection.Any())
{
<ul>
@foreach (var item in selection)
{
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
}

View File

@@ -15,12 +15,15 @@
@{ var propertyAlias = Model.MacroParameters["propertyAlias"]; }
@if (propertyAlias != null)
{
var selection = CurrentPage.Children.Where("Visible").OrderBy(propertyAlias);
var selection = Model.Content.Children.Where(x => x.IsVisible()).OrderBy(x => x.GetPropertyValue(propertyAlias.ToString()));
<ul>
@foreach (var item in selection)
{
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
@if (selection.Any())
{
<ul>
@foreach (var item in selection)
{
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
}
}

View File

@@ -1,17 +1,13 @@
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@*
This snippet shows how simple it is to fetch only children of a certain Document Type using Razor.
Be sure to change "DocumentTypeAlias" below to match your needs, such as "TextPage" or "NewsItems".
This snippet shows how simple it is to fetch only children of a certain Document Type.
Be sure to change "IPublishedContent" below to match your needs, such as "TextPage" or "NewsItem".
(You can find the alias of your Document Type by editing it in the Settings section)
*@
@{ var selection = CurrentPage.Children("DocumentTypeAlias").Where("Visible"); }
@*
As an example of more querying, if you have a true/false property with the alias of shouldBeFeatured:
var selection= CurrentPage.Children("DocumentTypeAlias").Where("shouldBeFeatured == true").Where("Visible");
*@
@{ var selection = Model.Content.Children<IPublishedContent>().Where(x => x.IsVisible()); }
@if (selection.Any())
{

View File

@@ -5,13 +5,13 @@
the page currently being viewed by the website visitor, displayed as nested unordered html lists.
*@
@{ var selection = CurrentPage.Children.Where("Visible"); }
@{ var selection = Model.Content.Children.Where(x => x.IsVisible()); }
@* Ensure that the Current Page has children *@
@if (selection.Any())
{
@* Get the first page in the children, where the property umbracoNaviHide is not True *@
var naviLevel = CurrentPage.FirstChild().Where("Visible").Level;
var naviLevel = Model.Content.FirstChild(x => x.IsVisible()).Level;
@* Add in level for a CSS hook *@
<ul class="level-@naviLevel">
@@ -22,7 +22,7 @@
<a href="@item.Url">@item.Name</a>
@* if this child page has any children, where the property umbracoNaviHide is not True *@
@if (item.Children.Where("Visible").Any())
@if (item.Children.Where(x => x.IsVisible()).Any())
{
@* Call our helper to display the children *@
@childPages(item.Children)
@@ -33,7 +33,7 @@
}
@helper childPages(dynamic selection)
@helper childPages(IEnumerable<IPublishedContent> selection)
{
@* Ensure that we have a collection of pages *@
if (selection.Any())
@@ -43,13 +43,13 @@
@* Add in level for a CSS hook *@
<ul class="level-@(naviLevel)">
@foreach (var item in selection.Where("Visible"))
@foreach (var item in selection.Where(x => x.IsVisible()))
{
<li>
<a href="@item.Url">@item.Name</a>
@* if the this page has any children, where the property umbracoNaviHide is not True *@
@if (item.Children.Where("Visible").Any())
@if (item.Children.Where(x => x.IsVisible()).Any())
{
@* Call our helper to display the children *@
@childPages(item.Children)

View File

@@ -16,8 +16,8 @@
@if (mediaId != null)
{
@* Get all the media item associated with the id passed in *@
var media = Umbraco.Media(mediaId);
var selection = media.Children("Image");
var media = Umbraco.TypedMedia(mediaId);
var selection = media.Children<Image>();
if (selection.Any())
{
@@ -25,7 +25,7 @@
@foreach (var item in selection)
{
<li>
<img src="@item.umbracoFile" alt="@item.Name" />
<img src="@item.Url" alt="@item.Name" />
</li>
}
</ul>

View File

@@ -8,14 +8,16 @@
multinode treepicker (so: replace "PropertyWithPicker" with the alias of your property).
*@
@{ var selection = CurrentPage.PropertyWithPicker.Split(','); }
@{ var selection = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("PropertyWithPicker"); }
<ul>
@foreach (var id in selection)
{
var item = Umbraco.Content(id);
<li>
<a href="@item.Url">@item.Name</a>
</li>
}
</ul>
@if (selection.Any())
{
<ul>
@foreach (var item in selection)
{
<li>
<a href="@item.Url">@item.Name</a>
</li>
}
</ul>
}

View File

@@ -6,13 +6,16 @@
It also highlights the current active page/section in the navigation with the css class "current".
*@
@{ var selection = CurrentPage.Site().Children.Where("Visible"); }
@{ var selection = Model.Content.Site().Children.Where(x => x.IsVisible()); }
<ul>
@foreach (var item in selection)
{
<li class="@(item.IsAncestorOrSelf(CurrentPage) ? "current" : null)">
<a href="@item.Url">@item.Name</a>
</li>
}
</ul>
@if (selection.Any())
{
<ul>
@foreach (var item in selection)
{
<li class="@(item.IsAncestorOrSelf(Model.Content) ? "current" : null)">
<a href="@item.Url">@item.Name</a>
</li>
}
</ul>
}

View File

@@ -7,7 +7,7 @@
- It uses a custom Razor helper called Traverse() to select and display the markup and links.
*@
@{ var selection = CurrentPage.Site(); }
@{ var selection = Model.Content.Site(); }
<div class="sitemap">
@* Render the sitemap by passing the root node to the traverse helper, below *@
@@ -15,14 +15,14 @@
</div>
@* Helper method to travers through all descendants *@
@helper Traverse(dynamic node)
@* Helper method to traverse through all descendants *@
@helper Traverse(IPublishedContent node)
{
@* Update the level to reflect how deep you want the sitemap to go *@
var maxLevelForSitemap = 4;
@* Select visible children *@
var selection = node.Children.Where("Visible").Where("Level <= " + maxLevelForSitemap);
var selection = node.Children.Where(x => x.IsVisible() && x.Level <= maxLevelForSitemap);
@* If any items are returned, render a list *@
if (selection.Any())