Hello.
1st of all I’m using version 7.3.3 with fanoe starter kit.
I am trying to find the best and not that hard way to filter the blog post by some “options” that i have Created.
I have created new properties on the “blog spot” document type. one is “Country” and the second one is “Project type”
i managed to get the existing values on both of them and place then on even get the selected value by javascript by I’m stack on the filtering of the data.
have a look at what i have added to the “Blog Overview” template.
@{
var posts = CurrentPage.Children;
var usedcountries = new List<string>();
var usedProjectTypes = new List<string>();
}
<div class="col-sm-3">
@foreach (var post in posts)
{
if (!usedcountries.Contains(post.countries))
{
usedcountries.Add(post.countries);
};
}
@{usedcountries.Sort();}
<select id="theCountry">
<option value="none">Any Country</option>
@foreach (var c in usedcountries)
{
<option value="@c">@c</option>
}
</select>
</div>
<div class="col-sm-6">
@foreach (var post in posts)
{
if (!usedProjectTypes.Contains(post.projectType))
{
usedProjectTypes.Add(post.projectType);
};
}
@{usedProjectTypes.Sort();}
<select id="theType">
<option value="none">Any Project Type</option>
@foreach (var p in usedProjectTypes)
{
<option value="@p">@p</option>
}
</select>
</div>
<div class="col-sm-3">
<button onclick="myReloadFunction()">Search</button>
<script>
function myReloadFunction() {
var e = document.getElementById("theCountry");
var _theSelectedCountry = e.options[e.selectedIndex].value;
var e = document.getElementById("theType");
var _theSelectedType = e.options[e.selectedIndex].value;
}
</script>
</div>
</div>
FYI - i still don’t know much about XSLT.. i know good Linq and maybe an API solution might fit.. but I might be wrong.,.
Thanks.
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/74982-filter-blog-posts