Hey, I'm new to Umbraco and hoping somebody could help me with this issue.
I have a parent page, 'Our Products'. This page has the page 'Product Page' set as it's child page. This 'Product Page' holds data about a product such as it's title, description, and tags which will be used for search functionality.
I'm currently editing the code within the 'Our Products' page to try and retrieve some products with specific tags. This is the code I've tried to create so far.
@{
var searchTagsCriteria = "Tag1";
var selection = Model.Content.Site().FirstChild("ourProductsPage").Children()
.Where(x => x.IsVisible())
.Where(x => x.GetPropertyValue<IEnumerable<string>>("productType").Contains(searchTagsCriteria));
}
<ul>
@foreach(var item in selection){
<li>
<a href="@item.Url">@item.Name</a>
</li>
}
</ul>
This doesn't cause any compilation error, although it doesn't produce any results. I know that one of my products has a tag 'Tag1', so why can't I see this? I have a feeling I'm doing something wrong getting the tags correctly, but I'm not sure how to advance.
This is a belated reply but I wrote almost the exact code you have and it didn't work...the reason is that the tag or category you fetch likely has some formatting to it for some unknown reason - stripping those values out and then running the filter worked for me.
Example:
// The tag or category name you fetched
// might have internal formatting,
// e.g., new line/carriage return, spaces, and [ and ] characters
var cleanTagName = tagName
.Replace("\r\n", "")
.Replace("\"", "")
.Replace("[", "")
.Replace("]", "")
.Trim();
Searching for child nodes based on their tags
Hey, I'm new to Umbraco and hoping somebody could help me with this issue.
I have a parent page, 'Our Products'. This page has the page 'Product Page' set as it's child page. This 'Product Page' holds data about a product such as it's title, description, and tags which will be used for search functionality.
I'm currently editing the code within the 'Our Products' page to try and retrieve some products with specific tags. This is the code I've tried to create so far.
This doesn't cause any compilation error, although it doesn't produce any results. I know that one of my products has a tag 'Tag1', so why can't I see this? I have a feeling I'm doing something wrong getting the tags correctly, but I'm not sure how to advance.
Any guidance is appreciated.
This is a belated reply but I wrote almost the exact code you have and it didn't work...the reason is that the tag or category you fetch likely has some formatting to it for some unknown reason - stripping those values out and then running the filter worked for me.
Example:
// The tag or category name you fetched
// might have internal formatting,
// e.g., new line/carriage return, spaces, and [ and ] characters
var cleanTagName = tagName
.Replace("\r\n", "")
.Replace("\"", "")
.Replace("[", "")
.Replace("]", "")
.Trim();
var items = posts.Children()
.Where(x => x.IsVisible())
.Where(x => x.GetPropertyValue<IEnumerable<string>< ("tags").Contains(cleanTagName ));
is working on a reply...