Yeah after thinking more about it the only way to find a template by its alias is to go to the database. The API should be fine if you're not doing it a lot, but be careful if you're using it a lot there'll be lots of DB calls ;).
If you really need to do it a lot maybe wrap the call in a custom API which you can add caching to.
Find node from template alias
Hello.
I have a working code sample from this forum which finds alle Content nodes with a specific DocumentType by alias
DocumentType dt = DocumentType.GetByAlias("Mappe");
Content[] docs = Document.getContentOfContentType(dt);
What I want to do is find all nodes which use a specific template by the alias of the template, how would I do this?
Hi Jacob,
Quick example using XSLT, but this relies on knowing the template's ID - not the alias name.
There's probably a way of doing this in C# using Linq2Umbraco ... or at an extreme a direct database call?
Cheers, Lee.
Nope LINQ to Umbraco (at least the NodeDataProvider) doesn't expose template alias, that's not stored in the published cache so it can't
I was curious to what the SQL query needed to query the database directly:
Then you would loop through each of the nodeId values, getting a Content or Document object, or even using the nodeFactory?
Cheers, Lee.
Yeah after thinking more about it the only way to find a template by its alias is to go to the database. The API should be fine if you're not doing it a lot, but be careful if you're using it a lot there'll be lots of DB calls ;).
If you really need to do it a lot maybe wrap the call in a custom API which you can add caching to.
Thanks for the input, ill go the db way.
I will do it so I only have to alter my code in 1 place if the db structure should be changed at some point.
is working on a reply...