Skip to content

Commit

Permalink
Initial commit of macro stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
Per Ploug committed Aug 15, 2012
1 parent 1a37efc commit ccad32a
Show file tree
Hide file tree
Showing 13 changed files with 512 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Stubs/cshtml/EmptyTemplate.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@inherits umbraco.MacroEngines.DynamicNodeContext

@*
Model = The current page the macro is executed on
@Model.bodyText
Parameter = collection of parameter values passed from the macro
@Paramter.myParam
*@



@* The fun starts here *@

16 changes: 16 additions & 0 deletions Stubs/cshtml/ListAncestorsFromCurrentPage.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@inherits umbraco.MacroEngines.DynamicNodeContext

@* Check the current page has ancestors *@
@if (Model.Ancestors().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 page in Model.Ancestors().OrderBy("Level"))
{
<li><a href="@page.Url">@page.Name</a> &raquo;</li>
}

@* Display the current page as the last item in the list *@
<li>@Model.Name</li>
</ul>
}
24 changes: 24 additions & 0 deletions Stubs/cshtml/ListChildMediaItemsFromMediaFolder.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@inherits umbraco.MacroEngines.DynamicNodeContext

@*
Macro Parameters To Create, for this macro to work:
Show:True Alias:mediaId Name:Media Folder ID Type:MediaCurrent
*@


@if (Parameter.mediaId != null)
{
@* Get the media folder as a dynamic node *@
var mediaFolder = Library.MediaById(Parameter.mediaId);

if (mediaFolder.Children.Any())
{
<ul>
@* for each item in children of the selected media folder *@
@foreach (var mediaItem in mediaFolder.Children)
{
<li><img src="@mediaItem.umbracoFile" alt="@mediaItem.Name" /></li>
}
</ul>
}
}
26 changes: 26 additions & 0 deletions Stubs/cshtml/ListChildPagesFromChangeableSource.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@inherits umbraco.MacroEngines.DynamicNodeContext
@*
=== Macro Parameters To Create ===
Show:True Alias:nodeId Name:Node ID Type:Content Picker
*@


@{
var startNodeID = Parameter.nodeId;
}

@if (startNodeID != null)
{
@* Get the start node as a dynamic node *@
var startNode = Library.NodeById(startNodeID);

if (startNode.Children.Where("Visible").Any())
{
<ul>
@foreach (var page in startNode.Children.Where("Visible"))
{
<li><a href="@page.Url">@page.Name</a></li>
}
</ul>
}
}
16 changes: 16 additions & 0 deletions Stubs/cshtml/ListChildPagesFromCurrentPage.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@inherits umbraco.MacroEngines.DynamicNodeContext


@* Ensure that the Current Page has children, where the property umbracoNaviHide is not True *@
@if (Model.Children.Where("Visible").Any())
{
<ul>
@* For each child page under the root node, where the property umbracoNaviHide is not True *@
@foreach (var childPage in Model.Children.Where("Visible"))
{
<li>
<a href="@childPage.Url">@childPage.Name</a>
</li>
}
</ul>
}
23 changes: 23 additions & 0 deletions Stubs/cshtml/ListChildPagesFromCurrentPageByDoctype.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@inherits umbraco.MacroEngines.DynamicNodeContext

@*
Macro Parameters To Create
Show:True Alias:contenType Name:Document Type Type:Textstring
*@

@{

@*Build a query and return the visible items *@
string query= "NodeTypeAlias == \"" + Parameter.contentType + "\"";
var selection= Model.Children.Where(query).Where("Visible");
}

@*Determine if there are any nodes in the selection, then render list *@
@if(selection.Any()){
<ul>
@foreach(var page in selection){
<li><a href="@page.Url">@page.Name</a></li>
}
</ul>
}

12 changes: 12 additions & 0 deletions Stubs/cshtml/ListChildPagesFromSiteRoot.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@inherits umbraco.MacroEngines.DynamicNodeContext

@{
var root = Model.AncestorsOrself(1)
}

<ul>
@foreach (var page in root.Children.Where("Visible"))
{
<li><a href="@page.Url">@page.Name</a></li>
}
</ul>
10 changes: 10 additions & 0 deletions Stubs/cshtml/ListChildPagesOrderedByDate.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@inherits umbraco.MacroEngines.DynamicNodeContext


<ul>
@*OrderBy() takes the property to sort by and optionally order desc/asc *@
@foreach (var page in Model.Children.Where("Visible").OrderBy("CreateDate desc"))
{
<li><a href="@page.Url">@page.Name</a></li>
}
</ul>
10 changes: 10 additions & 0 deletions Stubs/cshtml/ListChildPagesOrderedByName.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@inherits umbraco.MacroEngines.DynamicNodeContext


<ul>
@*OrderBy() takes the property to sort by*@
@foreach (var page in Model.Children.Where("Visible").OrderBy("Name"))
{
<li><a href="@page.Url">@page.Name</a></li>
}
</ul>
22 changes: 22 additions & 0 deletions Stubs/cshtml/ListChildPagesOrderedByProperty.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@inherits umbraco.MacroEngines.DynamicNodeContext

@*
Macro parameter to be set on the macro
Show:True Alias:propertyAlias Name:Property Alias Type:Textstring
*@


@{

@* Get the property alias we want to filter on from the macro parameter *@
var propertyAlias = Parameter.propertyAlias;
var selection = Model.Children.Where("Visible").OrderBy(propertyAlias)
}


<ul>
@foreach (var page in selection)
{
<li><a href="@page.Url">@page.Name</a></li>
}
</ul>
58 changes: 58 additions & 0 deletions Stubs/cshtml/ListDescendantsFromCurrentPage.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework


@* Ensure that the Current Page has children, where the property umbracoNaviHide is not True *@
@if (CurrentPage.Children.Where("umbracoNaviHide != @0", "True").Any())
{
@* Get the first page in the children, where the property umbracoNaviHide is not True *@
var naviLevel = CurrentPage.Children.Where("umbracoNaviHide != @0", "True").First().Level;

@* Add in level for a CSS hook *@
<ul class="level-@naviLevel">
@* For each child page under the root node, where the property umbracoNaviHide is not True *@
@foreach (var childPage in CurrentPage.Children.Where("umbracoNaviHide != @0", "True"))
{
<li>
<a href="@childPage.Url">@childPage.Name</a>

@* if the current page has any children, where the property umbracoNaviHide is not True *@
@if (childPage.Children.Where("umbracoNaviHide != @0", "True").Any())
{
@* Call our helper to display the children *@
@childPages(childPage.Children)
}
</li>
}
</ul>
}


@helper childPages(dynamic pages)
{
@* Ensure that we have a collection of pages *@
if (pages.Any())
{
@* Get the first page in pages and get the level *@
var naviLevel = pages.First().Level;

@* Add in level for a CSS hook *@
<ul class="level-@(naviLevel)">
@foreach (var page in pages.Where("umbracoNaviHide != @0", "True"))
{
<li>
<a href="@page.Url">@page.Name</a>

@* if the current page has any children, where the property umbracoNaviHide is not True *@
@if (page.Children.Where("umbracoNaviHide != @0", "True").Any())
{
@* Call our helper to display the children *@
@childPages(page.Children)
}
</li>
}
</ul>
}
}
62 changes: 62 additions & 0 deletions Stubs/cshtml/SiteMap.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework

@{
@* Walk up the tree from the current page to get the root node *@
var rootNode = CurrentPage.AncestorsOrSelf.Last();
}

@* Ensure that the Root Node has children, where the property umbracoNaviHide is not True *@
@if (rootNode.Children.Where("umbracoNaviHide != @0", "True").Any())
{
@* Get the first page in the children, where the property umbracoNaviHide is not True *@
var naviLevel = rootNode.Children.Where("umbracoNaviHide != @0", "True").First().Level;

@* Add in level for a CSS hook *@
<ul class="level-@naviLevel">
@* For each child page under the root node, where the property umbracoNaviHide is not True *@
@foreach (var childPage in rootNode.Children.Where("umbracoNaviHide != @0", "True"))
{
<li>
<a href="@childPage.Url">@childPage.Name</a>

@* if the current page has any children, where the property umbracoNaviHide is not True *@
@if (childPage.Children.Where("umbracoNaviHide != @0", "True").Any())
{
@* Call our helper to display the children *@
@childPages(childPage.Children)
}
</li>
}
</ul>
}


@helper childPages(dynamic pages)
{
@* Ensure that we have a collection of pages *@
if (pages.Any())
{
@* Get the first page in pages and get the level *@
var naviLevel = pages.First().Level;

@* Add in level for a CSS hook *@
<ul class="level-@(naviLevel)">
@foreach (var page in pages.Where("umbracoNaviHide != @0", "True"))
{
<li>
<a href="@page.Url">@page.Name</a>

@* if the current page has any children, where the property umbracoNaviHide is not True *@
@if (page.Children.Where("umbracoNaviHide != @0", "True").Any())
{
@* Call our helper to display the children *@
@childPages(page.Children)
}
</li>
}
</ul>
}
}
Loading

0 comments on commit ccad32a

Please sign in to comment.