I take it the search page isn't of a specific document type? That would be easy with something like:
var searchPage = CurrentPage.Site().FirstChild("ezSearch");
assuming you're using a new-ish version of Umbraco and have .Site() and .FirstChild(). If not, the old-fashioned, long-hand way would be:
var searchPage = CurrentPage.AncestorOrSelf(1).ezSearches.First();
Note that we're using the pluralized form of the document type alias, which I'm taking a wild guess is 'ezSearch' but if not then change that accordingly.
If you really must use templates as the only reliable way of finding the appropriate page then you're in good shape except you can't mix LINQ expressions with the simple .Where() syntax provided when using CurrentPage. If you want to use your lambda expressions you'd need to use strongly-typed razor instead of CurrentPage.
So, assuming you want to use CurrentPage and check for a template it would be:
var rootPage = CurrentPage.Site(); //or .AncestorOrSelf(1)
var searchPage = rootPage.Children.Where("TemplateId == 1235").First();
Notice that the .Where() clause used for CurrentPage is a string.
Last thing to mention... in v7 you won't see the Id number of the template listed in the back office as you used to do in earlier versions. To find the Id number, go to the Templates section of the tree and hover your mouse over the icon to the left of the name of the template you're interested in. You'll get a flyout tooltip that shows the Id number.
Finding first descendant with a specific template id ?
Hi Folks
How to get the first descendant where templateid = 123 from currentpage ?
Hi Sebsatian,
I think that last comment in this thread https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/52709-Filter-nodes-by-template-alias-in-Umbraco-7 could be interesting for you.
Hope this helps,
/Dennis
Hi Sebstian
I think you could use something like this:
Hope this helps,
/Dennis
Hej Dennis
Er der grund til at loope den igennem hvis man bare gør sådan her:
I was hoping to do something like this:
But that just vommits at me with an error looking like this:
"Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type"
If I leave out the WHERE part it works fine except that I get the wrong node.
Hi Sebastian
I think that's because CurrentPage is dynamic... try:
Hi, Sebastian,
I take it the search page isn't of a specific document type? That would be easy with something like:
assuming you're using a new-ish version of Umbraco and have .Site() and .FirstChild(). If not, the old-fashioned, long-hand way would be:
Note that we're using the pluralized form of the document type alias, which I'm taking a wild guess is 'ezSearch' but if not then change that accordingly.
If you really must use templates as the only reliable way of finding the appropriate page then you're in good shape except you can't mix LINQ expressions with the simple .Where() syntax provided when using CurrentPage. If you want to use your lambda expressions you'd need to use strongly-typed razor instead of CurrentPage.
So, assuming you want to use CurrentPage and check for a template it would be:
Notice that the .Where() clause used for CurrentPage is a string.
Last thing to mention... in v7 you won't see the Id number of the template listed in the back office as you used to do in earlier versions. To find the Id number, go to the Templates section of the tree and hover your mouse over the icon to the left of the name of the template you're interested in. You'll get a flyout tooltip that shows the Id number.
Clearer than mud I hope. Shout if not, my friend!
cheers,
doug.
Hi Doug
Correct, the search page is a general page but with another template. So your last example worked like a charm.
Thanx a lot :)
// Sebastian
is working on a reply...