U4-2644 - Partial View Macro restriction removal

Created by Casey Neehouse 19 Aug 2013, 13:23:09 Updated by Shannon Deminick 12 Sep 2013, 04:57:05

Relates to: U4-2815

There is a restriction that the Partial View Macro file can not be anywhere other than ~/Views/MacroPartial. This restriction throws an error.

I am wanting to dynamically swap the file to a 'themed' location. Request that the location validation be removed or at most validate the file is in the root path of the site.


Sebastiaan Janssen 09 Sep 2013, 14:35:23

Pull request: https://github.com/umbraco/Umbraco-CMS/pull/131

Shannon Deminick 10 Sep 2013, 01:03:53

I've looked in to why we throw an exception there and there's a reason for it. The macro system is currently a mess and the db table that stores macro information is not adequate to specifically determine a macro type based on the information that is in there. If you have a look at:


This is the method that determines a macro type based on the information in the db table. You can see the logic in the test:


If you change the path of a partial view macro to not exist inside of: "/Views/MacroPartials/" or "/App_Plugins//Views/MacroPartials" then it will not be determined to be a "Partial View Macro" and instead will be treated like a legacy razor macro.

Unfortunately there's not much we can do about this without upgrading the macro db table. I'd also like to overhaul the whole macro process: http://issues.umbraco.org/issue/U4-700

I'll have to close your pull request since this will actually produce some errors in the long run.

What you can do in the meantime is have each theme inside the folder:

~/App_Plugins/Theme1/Views/MacroPartial ~/App_Plugins/Theme2/Views/MacroPartial

and it would work.

I realize this isn't ideal but we need to fix the db table and engines to properly support this.

Shannon Deminick 10 Sep 2013, 01:21:30

Casey said:

"Ok. Not sure what i can do then. The macro type is already set by the point this error is thrown.

If what you are saying is true, how would the error ever be hit? Does it matter then?

My file paths are set in code, not via the macro."

Shannon Deminick 10 Sep 2013, 01:21:43

So what is the file path of your macro in the database?

I'm assuming then that you are saying that the macro type has been determined based on the correct file path set of the macro in the database and then you are changing at runtime?

If that is the case then yup sure it will work.

Shannon Deminick 10 Sep 2013, 01:23:49

That makes more sense if that is the case since I wasn't sure how the macro engine would have been executed in the first place. I've re-opened the pull request but need you to fix up the code that was commented on.

Casey Neehouse 10 Sep 2013, 01:25:01

That is correct. The database has a standard path and file. I swap at runtime to themed variation.

Shannon Deminick 10 Sep 2013, 01:27:04

Ok cool, if you wanna just fix up the pull request I'll merge it in (have commented inline on the codeblocks https://github.com/umbraco/Umbraco-CMS/pull/131)

Casey Neehouse 11 Sep 2013, 17:40:15

I resubmitted the pull request. Thanks Shannon!

Shannon Deminick 12 Sep 2013, 04:47:33

Cool will pull it in but I'm going to modify your events as they're still not quite right, will let you know once updated so you can review. Cheers!

Shannon Deminick 12 Sep 2013, 04:56:56

All done, if you wanna have a look here: dcd5decd3a5ba94ebf6d11b2b74f77d4ca24c341

Nice one!

Priority: Normal

Type: Feature (request)

State: Fixed

Assignee: Shannon Deminick

Difficulty: Normal


Backwards Compatible: True

Fix Submitted:

Affected versions:

Due in version: 6.2.0


Story Points: