I am storing some email templates(means samples, do not confuse with umbraco templates) in Umbraco back office. At some point I need to send email using this template(subject, body, cc, bcc, etc).
The problem is that I cannot get this content. When I get it by Id everything works fine. But I do not want to rely on id as it changes and decided to use path and cannot do that. I get NullReferenceException when I execute following:
contentCache.GetByRoute(true, "relative path to email template")
relative path looks like "/settings/emailtemplate/registrationtemplate"
Can anyone point me that is the problem as I am new to Umbraco and struggling to understand how should I do certain things.
P.S. Before I was trying to find content be doc type alias but again I could not succeed as I could not figure out what is the relation between IContent and IPublishedContent. I could get from ContentService by doc type id but for auto generated models I need to use IPublishedContent
If you are trying to access this in a razor view you could do the following:
Model.Content.Site().Decendents("myDocTypeAlias")
Bascially, if you have access to the Umbraco context in a request it should be fairly straight forward to get the documents by Alias.
Word of warning about using Decendents, it can have a negative impact on performance, if you know more details about the structure of your site you might be better to use a mix of things like Decendents and Children to get the information.
Cannot return the IPublishedContent because the UmbracoHelper was constructed with an UmbracoContext and the current request is not a front-end request."`
It seems that it is because I am trying to get content from umbraco api controller. Is there a way to do it?
How can I get IPublishedContent by doc type?
Hi umbracians,
I am storing some email templates(means samples, do not confuse with umbraco templates) in Umbraco back office. At some point I need to send email using this template(subject, body, cc, bcc, etc).
The problem is that I cannot get this content. When I get it by Id everything works fine. But I do not want to rely on id as it changes and decided to use path and cannot do that. I get NullReferenceException when I execute following:
relative path looks like "/settings/emailtemplate/registrationtemplate" Can anyone point me that is the problem as I am new to Umbraco and struggling to understand how should I do certain things.
P.S. Before I was trying to find content be doc type alias but again I could not succeed as I could not figure out what is the relation between IContent and IPublishedContent. I could get from ContentService by doc type id but for auto generated models I need to use IPublishedContent
Hi Aman,
Is this code executing in a place where you have access to a current Umbraco model. For example within a surface controller?
If you were in a surface controller for example you could do the following:
This would return an IEnumerable
If you are trying to access this in a razor view you could do the following:
Bascially, if you have access to the Umbraco context in a request it should be fairly straight forward to get the documents by Alias.
Word of warning about using Decendents, it can have a negative impact on performance, if you know more details about the structure of your site you might be better to use a mix of things like Decendents and Children to get the information.
Nik
Hi Nik,
I am getting this error:
It seems that it is because I am trying to get content from umbraco api controller. Is there a way to do it?
is working on a reply...