I have a razor script which powers a simple website search. It works fine except some of my content nodes don't have templates associated with them - they're just items in a list. So when the search finds one of these items I want to link to the parent page and display the whole list of items rather than a link to the node itself which has no template and shouldn't be a 'page' in it's own right.
The code isn't optimised here, but it should show clearly what I'm trying to do:
When the search result is of document type 'SubPage' the link should show the parent of that node, not the node itself.
The problem is that on saving this I get an error, presumably because the Examine object doesn't store parent data:
Examine.SearchResult' does not contain a definition for 'Parent' and no extension method 'Parent' accepting a first argument of type 'Examine.SearchResult' could be found (are you missing a using directive or an assembly reference?)
What's the simplest way to get around this and return the parent URL of the current search result in the loop?
Get parent of examine search result with Razor
Hi,
I have a razor script which powers a simple website search. It works fine except some of my content nodes don't have templates associated with them - they're just items in a list. So when the search finds one of these items I want to link to the parent page and display the whole list of items rather than a link to the node itself which has no template and shouldn't be a 'page' in it's own right.
The code isn't optimised here, but it should show clearly what I'm trying to do:
When the search result is of document type 'SubPage' the link should show the parent of that node, not the node itself.
The problem is that on saving this I get an error, presumably because the Examine object doesn't store parent data:
Examine.SearchResult' does not contain a definition for 'Parent' and no extension method 'Parent' accepting a first argument of type 'Examine.SearchResult' could be found (are you missing a using directive or an assembly reference?)
What's the simplest way to get around this and return the parent URL of the current search result in the loop?
Thanks folks.
within the for loop you could do something like:
var node = Model.NodeById(result.Id);
node.Parent.NiceUrl
You probably get rid of the if clause as well by using .AncestorsOrSelf(string nodeTypeAlias)
is working on a reply...