An argument for using Macro Partial Views instead of just Partial Views
So, I ran into an issue with using Partial View in my Views and development.
Based off of the training from Umbraco, developers are supposed to use Macro Partial View ionly for things that the content authors are entering into content, such as a slideshow directly into BodyText. And then use Partial Views for things that Content Editors won't be adding into content (navigation, sidebar widgets, etc.)
So the thing I like about using Macro Scripts or Macro Partial Views is that the Macros degrade gracefully, or at least they give you a message that states the Macro could not be loaded without killing the whole page.
Solely using Partial Views to generate page elements, if your syntax is wrong in ANY way, the whole View is hosed. So if you are just happening to develop or making changes to a Partial View on a live site (I know, not good practice), then your whole site pages with those Views trying to render the Partial View are completely broken until you can figure out the syntax error.
Is there a better way in Umbraco that if a Partial View can not be rendered correctly, that is does not kill the whole View or template?
And if you need to pass a parameter, then you want to use Partial View Macro Files as it is wrapped in a macro and can support taking a paramater passed from your template. If you don't need to pass a parameter to your view, then a Partial View can be used.
I totally get why to use Partial View instead of Macro Partial Views and I agree with the direction.
HOWEVER, if a Partial View breaks or let's say I needed to make a quick change to a Partial View and made a simple typo, the WHOLE page or all pages using that View/Template with that View break, unlike Macros where it outputs a message saying that the Macro could not be rendered. I was just wondering if Umbraco had a better way to handle Partial View breaks so the whole page does not break if the code in the Partial View is slightly off.
You could log the error in the catch block too if you like.
By the way, Umbraco actually has a configuration setting to force the entire page to break when partial view macros break. Not something you would want, but just something to keep in mind (personally, I'd rather be made aware of an error so I can fix it rather than have it silently fail).
An argument for using Macro Partial Views instead of just Partial Views
So, I ran into an issue with using Partial View in my Views and development.
Based off of the training from Umbraco, developers are supposed to use Macro Partial View ionly for things that the content authors are entering into content, such as a slideshow directly into BodyText. And then use Partial Views for things that Content Editors won't be adding into content (navigation, sidebar widgets, etc.)
So the thing I like about using Macro Scripts or Macro Partial Views is that the Macros degrade gracefully, or at least they give you a message that states the Macro could not be loaded without killing the whole page.
Solely using Partial Views to generate page elements, if your syntax is wrong in ANY way, the whole View is hosed. So if you are just happening to develop or making changes to a Partial View on a live site (I know, not good practice), then your whole site pages with those Views trying to render the Partial View are completely broken until you can figure out the syntax error.
Is there a better way in Umbraco that if a Partial View can not be rendered correctly, that is does not kill the whole View or template?
Thanks
Carlos
Hi Carlos,
If you havenĀ“t seen the blogpost from Warren Buckly about Partials then maybe you can see when he mean that you should use Partial views or Partial macro views. http://creativewebspecialist.co.uk/2013/07/17/umbraco-mvc-is-the-macro-as-useful-in-v6-with-partials/
And if you need to pass a parameter, then you want to use Partial View Macro Files as it is wrapped in a macro and can support taking a paramater passed from your template. If you don't need to pass a parameter to your view, then a Partial View can be used.
Partial views: http://our.umbraco.org/documentation/Reference/Mvc/partial-views
Partial view macros. http://our.umbraco.org/documentation/Reference/Templating/Macros/Partial-View-Macros/
Hope this helps,
/Dennis
Hi Carlos,
Brain Flush has also written a blogpost about Umbraco: Partial View VS Partial View Macro.http://blogs.markglibres.com/2014/11/umbraco-partial-view-vs-partial-view.html
/Dennis
@Dennis,
I totally get why to use Partial View instead of Macro Partial Views and I agree with the direction.
HOWEVER, if a Partial View breaks or let's say I needed to make a quick change to a Partial View and made a simple typo, the WHOLE page or all pages using that View/Template with that View break, unlike Macros where it outputs a message saying that the Macro could not be rendered. I was just wondering if Umbraco had a better way to handle Partial View breaks so the whole page does not break if the code in the Partial View is slightly off.
-Carlos
You could always do this:
You could log the error in the catch block too if you like.
By the way, Umbraco actually has a configuration setting to force the entire page to break when partial view macros break. Not something you would want, but just something to keep in mind (personally, I'd rather be made aware of an error so I can fix it rather than have it silently fail).
@Nicholas
Hmmm. I guess we could to that on our Partials. I guess in the catch we could just print out an error if the Partial did not load.
is working on a reply...