Query to find children where MNTP value is selected
Hi All!
I'm still getting my feet wet with Umbraco and have a critical use case for our content authoring experience i'm hoping someone can help us resolve. We have a use case where we are using a doc type without template to create "categories" in a global location, a doc called "activity" which contains an MNTP field to select applicable "categories" items from the tree, and then a doc with template called "activity list" which also contains an MNTP field to select "categories" of which we want to query to show all children that also have those same "categories" for rendering in the results listing.
I have been able to successfully execute the desired functionality using dropdown list property editors however MNTP is desired because I can then have content authors add "categories" in the backoffice while keeping their role restricted from the "Settings" section. We also will use each "category" to create a tabbed list look so only results of one category match shows at a time.
Here's an additional breakdown on my editors and aliases:
Activity List Doc:
"activitySearchInitial" - MNTP field to select which items of a category show.
"activitySearchCategories" - MNTP field to select all categories to show in the page (listed as tab items or list-items in the same front-end now)
"attractionListCategories" - dropdown multi-select field currently working as expected
"attractionListCategoryDefault" - dropdown single-select field current working as expected
Activity Doc:
"activityCategories" - MNTP field containing all applicable categories for an activity
"attractionCategories" - dropdown multi-select field current working as expected
My question is - how would I rewrite the query where clause to check if the child of doctype "activity" contains one of the MNTP items selected on the doctype "activity list"?
Sample template view
@inherits Umbraco.Web.Mvc.UmbracoViewPage
@{
Layout = "HFEMaster.cshtml";
}
@Html.GetGridHtml(Model, "topGrid")
<div class="container">
@{
IPublishedContent attrStartPath = Model.Value<IPublishedContent>("startPath");
var defaultCategory = Model.Value("attractionListCategoryDefault");
var queryCategory = Request.QueryString["attractioncategory"];
var categories = Model.Value<IEnumerable<string>>("attractionListCategories");
var activityInitial = Model.Value<IEnumerable<IPublishedContent>>("activitySearchInitial");
var activityCategories = Model.Value<IEnumerable<IPublishedContent>>("activitySearchCategories");
var selection = (queryCategory != null)
? Umbraco.Content(attrStartPath.Id)
.DescendantsOfType("activity")
.Where(x => x.IsVisible() && x.Value<IEnumerable<string>>("attractionCategories").Contains(queryCategory))
.OrderBy(x => x.Name)
: Umbraco.Content(attrStartPath.Id)
.DescendantsOfType("activity")
.Where(x => x.IsVisible() && x.Value<IEnumerable<string>>("attractionCategories").Contains(defaultCategory))
.OrderBy(x => x.Name);
}
<p>Here's the MNTP default on Activity List:</p>
<ul>
@foreach (var item in activityInitial)
{
<li><a href="[email protected]">@item.Value("categoryTitle")</a></li>
}
</ul>
<p>Here's all the MNTP categories on Activity List:</p>
<ul>
@foreach (var category in activityCategories)
{
<li><a href="[email protected]">@category.Value("categoryTitle")</a></li>
}
</ul>
<p>Here's all the activity items that match the dropdown list values since MNTP in query is not working:</p>
<div class="row">
@foreach (var item in selection)
{
<div class="col-md-4">
<a href="@item.Parent.Url">
@{
var typedMediaPickerSingle = item.Value<IPublishedContent>("thumbnail");
if (typedMediaPickerSingle != null)
{
<img src="@typedMediaPickerSingle.Url" alt="@typedMediaPickerSingle.Value("alt")" />
}
}
</a>
<h3>@item.Value("activityTitle")</h3>
<p>@item.Value("shortDescription")</p>
<p><a href="@item.Parent.Url" class="btn btn-primary">Ride Details</a></p>
</div>
}
</div>
</div>
@Html.GetGridHtml(Model, "bottomGrid")
My question is - how would I rewrite the query where clause to check
if the child of doctype "activity" contains one of the MNTP items
selected on the doctype "activity list"?
If I understand this correctly, this sounds more like a LINQ question?
Query to find children where MNTP value is selected
Hi All!
I'm still getting my feet wet with Umbraco and have a critical use case for our content authoring experience i'm hoping someone can help us resolve. We have a use case where we are using a doc type without template to create "categories" in a global location, a doc called "activity" which contains an MNTP field to select applicable "categories" items from the tree, and then a doc with template called "activity list" which also contains an MNTP field to select "categories" of which we want to query to show all children that also have those same "categories" for rendering in the results listing.
I have been able to successfully execute the desired functionality using dropdown list property editors however MNTP is desired because I can then have content authors add "categories" in the backoffice while keeping their role restricted from the "Settings" section. We also will use each "category" to create a tabbed list look so only results of one category match shows at a time.
Here's an additional breakdown on my editors and aliases:
Activity List Doc: "activitySearchInitial" - MNTP field to select which items of a category show. "activitySearchCategories" - MNTP field to select all categories to show in the page (listed as tab items or list-items in the same front-end now) "attractionListCategories" - dropdown multi-select field currently working as expected "attractionListCategoryDefault" - dropdown single-select field current working as expected
Activity Doc: "activityCategories" - MNTP field containing all applicable categories for an activity "attractionCategories" - dropdown multi-select field current working as expected
My question is - how would I rewrite the query where clause to check if the child of doctype "activity" contains one of the MNTP items selected on the doctype "activity list"?
Sample template view
If I understand this correctly, this sounds more like a LINQ question?
I have created a quick sample project, that uses a third party library to make my razor more readable : https://gitlab.com/umbracohowto/ourumbraco106767
If this is what you are trying to achieve, then let me know, I'll see how it can be done in your code too.
is working on a reply...