Last active
October 8, 2019 23:45
-
-
Save naepalm/2ce4f7314658879cda16 to your computer and use it in GitHub Desktop.
An example of different ways to code the Umbraco FAQ Package's content.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using FAQ | |
@inherits UmbracoTemplatePage | |
@{ | |
Layout = null; | |
} | |
<h1>@Model.Content.Name</h1> | |
<h2>Render All FAQ Items</h2> | |
@if (Model.Content.HasProperty("faq") && Model.Content.HasValue("faq")) | |
{ | |
<ul> | |
@foreach (var q in Model.Content.GetPropertyValue<FAQListing>("faq").Items) | |
{ | |
<li> | |
<h3>@q.Question</h3> | |
@q.Answer | |
<p> | |
Categories: | |
@foreach (var category in q.Categories) | |
{ | |
if (category != q.Categories.FirstOrDefault()) | |
{ | |
@(string.Format(", {0}", category)) | |
} | |
else | |
{ | |
@category | |
} | |
} | |
</p> | |
</li> | |
} | |
</ul> | |
} | |
<hr /> | |
<h2>Render FAQ Items By Category</h2> | |
@if (Model.Content.HasProperty("faq") && Model.Content.HasValue("faq")) | |
{ | |
var categories = Model.Content.GetPropertyValue<FAQListing>("faq").Categories; | |
<ul> | |
@foreach (var category in categories) | |
{ | |
<li> | |
<h3>@category</h3> | |
@if (Model.Content.GetPropertyValue<FAQListing>("faq").Items.Any(x => x.Categories.Any(y => y.Contains(category)))) | |
{ | |
<ul> | |
@foreach (var q in Model.Content.GetPropertyValue<FAQListing>("faq").Items.Where(x => x.Categories.Any(y => y.Contains(category)))) | |
{ | |
<li> | |
<h3>@q.Question</h3> | |
@q.Answer | |
<p> | |
Categories: | |
@foreach (var cat in q.Categories) | |
{ | |
if (cat != q.Categories.FirstOrDefault()) | |
{ | |
@(string.Format(", {0}", cat)) | |
} | |
else | |
{ | |
@cat | |
} | |
} | |
</p> | |
</li> | |
} | |
</ul> | |
} | |
</li> | |
} | |
</ul> | |
} | |
<hr /> | |
<h2>Render FAQ Items by Querystring</h2> | |
@if (Model.Content.HasProperty("faq") && Model.Content.HasValue("faq")) | |
{ | |
var category = Request.QueryString["category"]; | |
var questions = !string.IsNullOrEmpty(category) ? Model.Content.GetPropertyValue<FAQListing>("faq").Items.Where(x => x.Categories.Any(y => y.Contains(category))) : Model.Content.GetPropertyValue<FAQListing>("faq").Items; | |
if (questions.Any()) | |
{ | |
var count = questions.Count(); | |
if (count > 1) | |
{ | |
<p>There are @count questions that match your query.</p> | |
} | |
else | |
{ | |
<p>There is 1 question that matches your query.</p> | |
} | |
<ul> | |
@foreach (var q in questions) | |
{ | |
<li> | |
<h3>@q.Question</h3> | |
@q.Answer | |
<p> | |
Categories: | |
@foreach (var cat in q.Categories) | |
{ | |
if (cat != q.Categories.FirstOrDefault()) | |
{ | |
@MvcHtmlString.Create(string.Format(", <a href=\"?category={0}\">{1}</a>", cat, cat)) | |
} | |
else | |
{ | |
<a href="[email protected](cat)">@cat</a> | |
} | |
} | |
</p> | |
</li> | |
} | |
</ul> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment