I'm trying to incorporate shopping/cart features from a remote web service into my site design. Particular pages need to check the status of the cart and redirect when items have expired, preferably before doing any further unnecessary processing or rendering.
I can accomplish this through a child action placed at the top of an Umbraco template (view), but this seems ugly to me. In an ordinary MVC Framework site, I would accomplish this via filters or attributes on controller methods, but this seems to be impossible with Umbraco pages.
Is there any way to execute custom, preliminary code on a per-page basis?
You could create a base template class that inherits from the main Umbraco one, set your master pages to use that instead of umbraco/masterpages/default.master (the default one), and then add your code to the new base page. That would then get called for every page. If you just wanted the checks on certain temnplates, only use your custom base class on the templates where you want to perform the checks.
Thanks for your reply! I may be wrong, but your solution seems to apply to Umbraco 4. In Umbraco 5, I suppose the equivalent of inheriting a master page would be to extend a layout. Shazwazza.com author, Shannon Deminick, advised me via comments to look into the Tasks API. Any thoughts on that?
Yup, my answer applies to v4, sorry I missed the MVC part! Shannons suggestions makes sense, I've not used the task API for v5 yet, so I can't advise on that sadly.
Best way to redirect when a cart expires?
I'm trying to incorporate shopping/cart features from a remote web service into my site design. Particular pages need to check the status of the cart and redirect when items have expired, preferably before doing any further unnecessary processing or rendering.
I can accomplish this through a child action placed at the top of an Umbraco template (view), but this seems ugly to me. In an ordinary MVC Framework site, I would accomplish this via filters or attributes on controller methods, but this seems to be impossible with Umbraco pages.
Is there any way to execute custom, preliminary code on a per-page basis?
Thanks,
Bryan
You could create a base template class that inherits from the main Umbraco one, set your master pages to use that instead of umbraco/masterpages/default.master (the default one), and then add your code to the new base page. That would then get called for every page. If you just wanted the checks on certain temnplates, only use your custom base class on the templates where you want to perform the checks.
Hope that helps!
Tim,
Thanks for your reply! I may be wrong, but your solution seems to apply to Umbraco 4. In Umbraco 5, I suppose the equivalent of inheriting a master page would be to extend a layout. Shazwazza.com author, Shannon Deminick, advised me via comments to look into the Tasks API. Any thoughts on that?
Bryan
Hiya,
Yup, my answer applies to v4, sorry I missed the MVC part! Shannons suggestions makes sense, I've not used the task API for v5 yet, so I can't advise on that sadly.
:(
is working on a reply...