Hi,
I am new to Umbraco (+code :-) and have a question about the query builder. It works fine and I get a list of teasers rendered out on the frontend. However I want to filter out the teaser for the current page. How can I do that?:
This is the output from the query builder:
Thanks for your quick reply!
If I am on a children page of page 1. I right now have all the children of page 1 as teasers on this children page- That works fine (I use a blocklist block with the query).
But I want all the children of page 1 except the children page that the user is on, since it does not make sense for the user to click on a teaser for a page that they are currently on. So I need to filter out the current children page, so that I can use the same blocklist block (with the same query builder) for each children page on page 1. (on page 2 I have another blocklist block with a new query builder).
...So on Page 1:Children 1 page the user is presented with a list of Page1:Children 2 and 3
...and on Page 1: Children 2 page the user is presented with a list of Page 1: Children 1 and 3.
I think I get it now what you want to achieve. Personally I like better to see the page I am on with an active class so I have 2 different things for you to try
@{
var selection = Umbraco.Content(Guid.Parse("e9e95459-24af-4e83-8bbd-959a6c4cad32"))
.Children()
.Where(x => x.IsVisible())
.OrderBy(x => x.Name);
if (selection != null && selection.Any())
{
//add an active class if is the current page
<ul>
@foreach (var item in selection)
{
var isCurrentPage = Model.Id == item.Id;
<li>
<a href="@(isCurrentPage == false ? item.Url: string.Empty)" class="@(isCurrentPage ? "active" : string.Empty)">@item.Name</a>
</li>
}
</ul>
//exclude the current page from the list
<ul>
@foreach (var item in selection)
{
var isCurrentPage = Model.Id == item.Id;
if (isCurrentPage == false)
{
<li>
<a href="@item.Url">@item.Name</a>
</li>
}
}
</ul>
}
}
Or exclude the page in your selection, so you dont have to change your code
Umbraco query builder
Hi, I am new to Umbraco (+code :-) and have a question about the query builder. It works fine and I get a list of teasers rendered out on the frontend. However I want to filter out the teaser for the current page. How can I do that?: This is the output from the query builder:
@{ var selection = Umbraco.Content(Guid.Parse("e9e95459-24af-4e83-8bbd-959a6c4cad32")) .Children() .Where(x => x.IsVisible()) .OrderBy(x => x.Name); }
Thanks in advance
Hi Mads,
If your nodes are like that
Home
-Page (document type alias"page")
Child 1
Child 2
Child 3
-Page 2 (document type alias "page2")
Child 1
Child 2
Child 3
And if you are on the page 1 and you want page1 children or if you are on the page 2 and you want page2 children then you can do that
If you are on the home page and you want the nodes of the page1 then you can do that
Hope that helps.
Thanks, T
Hi Thomas,
Thanks for your quick reply! If I am on a children page of page 1. I right now have all the children of page 1 as teasers on this children page- That works fine (I use a blocklist block with the query).
But I want all the children of page 1 except the children page that the user is on, since it does not make sense for the user to click on a teaser for a page that they are currently on. So I need to filter out the current children page, so that I can use the same blocklist block (with the same query builder) for each children page on page 1. (on page 2 I have another blocklist block with a new query builder). ...So on Page 1:Children 1 page the user is presented with a list of Page1:Children 2 and 3
...and on Page 1: Children 2 page the user is presented with a list of Page 1: Children 1 and 3.
Hope it makes sense.
Best regards Mads Vester
Hi Mads,
I think I get it now what you want to achieve. Personally I like better to see the page I am on with an active class so I have 2 different things for you to try
Or exclude the page in your selection, so you dont have to change your code
Let me know if that helped
Thanks again. I have tried both solutions, but I get a Runtime error on both :-/
Best regards Mads Vester
Hi Mads,
What's the error?
Thanks, T
is working on a reply...