-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathumbraco.html
178 lines (137 loc) · 5.58 KB
/
umbraco.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!--
Cheatsheet for umbraco (http://umbraco.com/)
-->
Special umbraco properties (see http://our.umbraco.org/wiki/reference):
- umbracoRedirect
- umbracoUrlName
- umbracoUrlAlias
- umbracoInternalRedirectId
- umbracoNaviHide
<asp:Content ContentPlaceHolderID="someID" runat="server">
<!-- Need to store all template code in here ... -->
<!-- CSS -->
<link rel="stylesheet" href="/css/style.css">
<!-- Document type property -->
<umbraco:Item field="bodyText" runat="server"/>
<!-- Recursively goes up the content tree for field value -->
<umbraco:Item field="bodyText" recursive="true" runat="server"/>
<!-- Reference developer macro -->
<umbraco:Macro macroAlias="topNavigation" Alias="topNavigation" runat="server" />
<!-- Umbraco inline razor script -->
<umbraco:Macro runat="server" language="cshtml">
@*
Multiline
comment
*@
@Html.Raw(model.Message)
@Model.Name
@Model.Url
@Model.Id
@Model.Children
@Model.Children.where("Visible")
@Model.Children.Count()
@Model.Children.Take(2)
@Model.Children.Skip(2)
@Model.Children.ElementAt(1)
@Model.Children.Where("shouldBeFeatured")
@Model.Children.Where(item => item.shouldBeFeatured)
@Model.Children.Where("shouldBeFeatured == true")
@Model.Children.Where("catCount > 1")
@Model.Children.Where("menuType == \"Top Menu\ || menuType == \"Bottom Menu\"")
@Model.Children.Where("bodyText.Contains(\"cat\")")
@Model.Children.Where("bodyText.Contains(\"cat\") || !(bodyText.Contains(\"dog\"))")
@Model.Children.Where("Name.Contains(\"cat\") || Name.Contains(\"dog\") || Name.Contains("\fish\")")
@Model.Children.OrderBy("catCount")
@Model.Children.OrderBy("catCount, colour desc")
@Model.NodeTypeAlias
@{
dynamic children = Model.AncesterOrSelf(1).Children // At level 1
dynamic list = Model.AncestorOrSelf(1).DescendantsOrSelf("ArticleTypeAlias").OrderBy("CreateDate desc").Take(5)
}
@Model.Ancestors()
@Model.XPath("//ChildItem[catCount > 4 and count(.//catPictures) > 0]")
@Parameter.siteName
// DynamicNodeWalker
Model.Down(1).Next().Down(1)
// Media
@VirtualPathUtility.ToAbsolute(Model.Media("some_file_attribute","umbracoFile"))
// Selecting a folder and displaying all the images in the folder
<umbraco:Macro runat="server" language="cshtml">
@* Could also try .IsNull() .HasValue() and Model.someProperty.GetType() == typeof(DynamicNull), but they don't seem to work properly *@
@if (!string.IsNullOrEmpty(@Model.GetProperty("imagesFolder").Value)) {
<ul>
@foreach(var image in Model.MediaById(Model.imagesFolder).Children) {
<li><img src="@VirtualPathUtility.ToAbsolute(@image.umbracoFile)" title="@image.Name"/></li>
}
</ul>
}
</umbraco:Macro>
// Strings
!string.IsNullOrEmpty(@someString)
// Conditionals
@if (condition) {
} else {
}
// Random
<umbraco:Macro runat="server" language="cshtml">
@{
int numOffers = Model.AncestorOrSelf(1).DescendantsOrSelf("SpecialOffer").Count();
Random random = new Random();
int randomIndex = random.Next(0, numOffers);
dynamic randomOffer = Model.AncestorOrSelf(1).DescendantsOrSelf("SpecialOffer").ElementAt(randomIndex);
dynamic randomOfferImage = randomOffer.Media("image", "umbracoFile");
}
<div class="block-content">
<a href="@randomOffer.link"><img src="@VirtualPathUtility.ToAbsolute(randomOfferImage)" alt="special offers" width="164" height="228" /></a>
</div>
</umbraco:Macro>
// Subpages
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
dynamic pages = Model.AncestorOrSelf(2).Children;
}
<ul id="primary_nav">
@foreach (var page in pages)
{
// Check whether it is an ancester page or the current page
dynamic pageCss = ((@Model.Ancestors().Where("Id == " + page.Id).Count() > 0) ||
(@Model.Id == page.Id)) ? "current" : "";
<li class="@pageCss"><a href="@page.Url">@page.Name</a></li>
if (page.Children.Count() > 0)
{
dynamic subpages = page.Children;
<ul>
@foreach (var subpage in subpages)
{
// Check whether it is the current page
dynamic subpageCss = (@Model.Id == subpage.Id) ? "current" : "";
<li class="@subpageCss"><a href="@subpage.Url">@subpage.Name</a></li>
}
</ul>
}
}
</ul>
// Items of a node id
<ul>
@{
dynamic newsId = 1063;
dynamic newsItems = new umbraco.MacroEngines.DynamicNode(newsId);
// Could also do Model.NodeById(newsId) - all you need is a DynamicNode to invoke NodeById
}
@foreach(var item in newsItems.Children.OrderBy("CreateDate")) {
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
// 'NewsItem' document types
@{
dynamic newsItems = Model.AncestorOrSelf(1).DescendantsOrSelf("NewsItem").OrderBy("CreateDate desc").Take(5);
}
<ul>
@foreach(var item in newsItems) {
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
@{ var num = 10; }
</umbraco:Macro>
</asp:Content>
<asp:ContentPlaceHolder ID="someID" runat="server"/> <!-- Reference someID content above -->