Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
An example of different ways to code the Umbraco FAQ Package's content.
@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="?category=@Html.Encode(cat)">@cat</a>
}
}
</p>
</li>
}
</ul>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment