@{
//Start at the root node
var nodes = traverse(Model.AncestorOrSelf());
}
<h1>Nodes with bodyText property that has a value</h1>
@foreach(var node in nodes)
{
@node.Name<br/>
}
@functions {
public List<dynamic> traverse(dynamic startNode)
{
var nodes = new List<dynamic>();
foreach (var item in startNode.Children)
{
if (item.HasProperty("bodyText") && item.HasValue("bodyText"))
{
nodes.Add(item);
}
//as this is recursive, it'll go through all of the content
traverse(item);
}
return nodes;
}
}
It would be difficult to get all the nodes and property data into a single table/view. (Guessing you mean like a pivot'd view with all properties as columns?)
When you say that you want to find all the nodes with a particular property set - do you mean nodes that have specific properties, or those with a specific value?
I've used the following T-SQL snippet for getting a list of node ids for properties with a specific value.
DECLARE @search NVARCHAR(50);
SET @search = 'green';
SELECT
n.id,
n.path
FROM
cmsPropertyData AS pd
INNER JOIN umbracoNode AS n ON n.id = pd.contentNodeId
INNER JOIN cmsDocument AS d ON n.id = d.nodeId
WHERE
d.newest = 1 AND d.versionId = pd.versionId
AND
(
pd.dataNvarchar LIKE ('%' + @search + '%')
OR
pd.dataNtext LIKE ('%' + @search + '%')
)
;
TSQL to get a nod eby id with related properties
Is there any way in TSQL to get a node with its properties as a table?
What I really need to do is find any nodes with a particular property set.
Any help would be really appreciated.
Rszor?
Hi Brendan,
It would be difficult to get all the nodes and property data into a single table/view. (Guessing you mean like a pivot'd view with all properties as columns?)
When you say that you want to find all the nodes with a particular property set - do you mean nodes that have specific properties, or those with a specific value?
I've used the following T-SQL snippet for getting a list of node ids for properties with a specific value.
Sure it can be adapted to suit your needs.
Cheers, Lee.
Thanks guys Lee that is more than what I need, really appreciate the help. Razor is good Seb but I need TSQL this time.
Thanks again.
How do a pivot'd view with all properties as columns?
is working on a reply...