How to access root content from a surfaceController?
Hi,
Slightly altering a working email form sending SurfaceController to pick up the "To" email address from a Settings page in the root of the site instead of picking it up from the page that has the form in it.
This worked when the "emailToAddress" was held in the "Contact" page:
var currentNode = Umbraco.TypedContent(UmbracoContext.PageId.GetValueOrDefault());
var toAddress = currentNode.GetProperty("emailAddress").Value.ToString();
However, when trying to access the address in the settings page (a sibling of root) it complains that Model does not exist:-
var settings = Model.Content.AncestorOrSelf(1).Sibling("Settings");
var toAddress = settings.GetPropertyValue("emailToAddress").ToString();
I guess it must be possible to access the data I need, I just don't have a clue how to go about it.
The cache is the published content cache of the website - its where umbraco goes to get a webpage when you visit it - so its loading from file rather than db.
If its published its in the cache (unless something wrong with the cache) :)
And Umbraco.TypedContent(id) returns IPublishedContent - which again if its not published wont find it.
If you want to retrieve an item whether its Published or not then use the ContentService Api.
Hope that makes things clear for you. :)
Damian
PS: and the item will remain in the published content cache while ever it is published. Only comes out when you unpublish.
Ah THAT cache. That's great, thanks for the clarification. Been doing some work on a (non-Umbraco) site using the server cache which was why I was open to "other" caches:)
How to access root content from a surfaceController?
Hi,
Slightly altering a working email form sending SurfaceController to pick up the "To" email address from a Settings page in the root of the site instead of picking it up from the page that has the form in it.
This worked when the "emailToAddress" was held in the "Contact" page:
However, when trying to access the address in the settings page (a sibling of root) it complains that Model does not exist:-
I guess it must be possible to access the data I need, I just don't have a clue how to go about it.
Any advice appreciated,
Craig
Hi Craig,
How about this?
Also rather than using typedcontent use the cache! :)
And to get the current page:
That any good?
Damian
Also the Sibling() extension is looking for contentType alias not name. You didnt say whether setting was your type or name.
You could do what yu have with a small tweak for type alias:
Thanks Damian.
The first one worked thanks. Don't like to use the cache but if there's no other way.
"Settings" is the alias though would prefer to do it by pageName so can now do either, thanks:)
As for the second one....... "The name 'Model' does not exist in the current context" still appears on build, (as you would expect?)
Cheers,
Craig
Why wouldn't you want to use the cache?
Model wont exist in the current context because you are in a surface controller.
You can use CurerntPage to get the current IPublishedContent - which is the same as the Model.Content in a partial.
Damian
Just that cache sounds temporary, might not be there, etc. Not actually sure which cache you mean as you didn't say.
But thanks anyway. All done and answer marked ;)
Cheers,
Craig
Good stuff...
Just to clear this up for you:
The cache is the published content cache of the website - its where umbraco goes to get a webpage when you visit it - so its loading from file rather than db.
If its published its in the cache (unless something wrong with the cache) :)
And Umbraco.TypedContent(id) returns IPublishedContent - which again if its not published wont find it.
If you want to retrieve an item whether its Published or not then use the ContentService Api.
Hope that makes things clear for you. :)
Damian
PS: and the item will remain in the published content cache while ever it is published. Only comes out when you unpublish.
Ah THAT cache. That's great, thanks for the clarification. Been doing some work on a (non-Umbraco) site using the server cache which was why I was open to "other" caches:)
Cheers,
Craig
is working on a reply...