Hacking about - viewLocations
# package-development
k
Hacking about - viewLocations
Having a bit of a hack about: i have been experimenting with the idea of how themes might work in Umbraco (e.g in a starter kit or similar). So it could be easy for the user to switch between look and feel, frameworks etc.
Having a bit of a hack about: i have been experimenting with the idea of how themes might work in Umbraco (e.g in a starter kit or similar). So it could be easy for the user to switch between look and feel, frameworks etc. One way to achieve this (with minimal having to write theme extensions and custom partial commands into views) might be to add locations to the folders that asp.net looks for .cshtml files in. (the viewLocations) This is fairly standard AspNet Core (and how Umbraco does it) - so I have some example code to add extra folders https://gist.github.com/KevinJump/2d981be4ed51a0ce3f071636d6a11f60
This 'Works' but only if you add the additional views before
AddWebsite()
is called in the startup.cs e.g
Copy code
services.AddUmbraco(_env, _config)
              .AddBackOffice()
              .AddAubergineThemes()
              .AddWebsite()
              .AddComposers()
              .Build();
However this has two problems: 1. you can't add the themes in a composer (so users would have to alter this file) 2. because Umbraco adds its views to the front of the list, they will always be found first, what I would want is the files in
/views/theme/mytheme/
to be used and fail back to
/views
looking at the code, I think this is probably because inside
AddWebsite()
models builder does something fancy to the views in
AddInMemoryModelsRazorEngine
(see https://github.com/umbraco/Umbraco-CMS/blob/5bfab13dc5a268714aad2426a2b68ab5561a6407/src/Umbraco.Web.Common/ModelsBuilder/DependencyInjection/UmbracoBuilderDependencyInjectionExtensions.cs#L142:L165) I think this is the point when any new config options are not being loaded into the
RazorViewEngineOptions
So question for the Umbraco brains, - do we think this is something that can be 'fixed' inside the core - so views can be added after Umbraco has added its own? (if so i am happy to see what that might mean.. but its a little out of my depth). - Is there infact another way to add views that would work currently? - Or is this baked into Umbraco and probably isn't the way to go?
p
Imagine autodiscovered IHostingStartup would help here, let me find link to discussion
Oh wasn't a discussion, was just a message in this channel https://discord.com/channels/869656431308189746/882984798719729704/898303301366448128
If implemented I think the theory is we wouldn't even need composers anymore as could just add to service collection from your hosting startup also.
but probably need pipeline setup to enable ordering.
In terms of overridable views, razor class libraries deserve a look. @User might have thoughts on what's achievable with this.
But then this is backoffice views so I guess you mean angular views as opposed to razor views? Can also go in an RCL, and for allowing loading from multiple providers e.g. from static files and falling back to embedded files etc it's worth looking into https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.fileproviders.compositefileprovider?view=dotnet-plat-ext-6.0
j
I really like the idea of packaging starter kits (and themes) in an RCL - not a huge fan of ingesting views in my project (now that I'm compiling them) but 🤷‍♂️ I'm not really that precious. Haven't managed to get a PoC starter kit in an RCL yet.
k
yeah this is razor views (not angular views)
p
I'm pretty sold on starter kits should be dotnet templates
because they are mutable, whereas packages etc not so much
What does a theme do, add classes, change markup?
k
in theory (and i mean i am really at the what is possible stage) - you might for example have a site that has a boiler plate set of templates, and themes would either let you replace them, or maybe replace the views.
think wordpress themes 😉
j
RCLs will do this 👆
But they will be Immutable
p
but overridable 🙂
j
Indeed
Very similar to Wordpress themes in that sense
(these days at least)
k
so do you mean RazorClassLibrary (sorry just checking). and that means the views are resources in a dll ?
j
Yep
It essentially ships the views in their compiled state
p
and looks for alternatives on filesystem for referencing project
except for static assets which needs extra work with composite file provider
k
OK, i will have a look, but i will say my intial opinion is this is quite overkill, would be a barrier to entry should you want other people to write themes/update things. I am however talking before i have tried. so willing to be proven wrong
p
this is for backoffice, backoffice really shouldn't have any razor at all
should be a decoupled frontend build
no i misunderstand, this is for theming a frontend site
k
no - its themes for a website, so not backoffice (although there might be a back office themese editor - that isn't the thing the razor would be for)
p
sorry, i caught up
k
no worries.
p
can we define theme vs starterkit?
j
That's the thing.
I think we need both
k
in this case (i still don't know what i am actually aming for). it would be.. 1. a starter kit you install, that is themeable. so the starter kit is a site, behaves like a site
but ...
it can have its theme changed, (by the user) so its look and feel could be picked, / frameworks maybe ?
p
that sounds like a good case for a dotnet template
k
yeah it really does, but adding / updating themes is the thing i think i would want to be able to do.
j
That could be done with RCLs
p
so a dotnet template that references an RCL 🙂
j
Both?
p
^^
k
and at the moment, the fact that umbraco doesn't let me add a folders to the views is stopping whati think might be a simple answer.
i am going to try RCLs 😄
p
why cant you add views at the moment?
k
top of the thread 😉 - you can but once AddWebsite() is called you can't
and Umbraco adds its views to the front of the list
so \views\mytemplate.cshtml is found before \views\themes\mytheme\mytemplate.cshtml
i would want that the otherway around so the theme fell back to the template
(example theme folder paths, could be anywhere)
p
ok so custom view locations you probably want the ihostingstartup stuff
which I'm hoping to hack on for v10
k
suppose TLDR was can we stop umbraco from stopping us adding RazorViewConfig after models builder is initialized ?
j
What I'd like to see is a WordPress equivalent - i.e. a theme that's immutable so that updates can be applied - v2, 2.1 etc. And a "starter kit" that sets you up with everything in a proj but you take ownership of the code/doctypes etc. from that point.
k
Just to say, i have come around to Jason's world view Razor Class Libraries are cool 😄
p
I got there first!
Although I think Jason took the idea a lot further than I did 😄
k
👍
At the moment it's only really things that are nodes in a tree that I can't move out of app_plugins
It probably can be tidies up even more, my build scripts will need a tidy for sure
p
wow so does this work already that was fast work
have you tried referencing it from nupkg, Jason mentioned something goes wrong with static assets when that happens, I haven't got round to trying yet (oh that was only when playing with StaticWebAssetBasePath)
k
Yeah build will be next, it might yet fall apart
it appears to work when you include it as a package. as far as i can tell its a very similar hack as to the one we are already using....
it generates a .props file that goes into your package during development , this means there is an xml file in obj\{enviornment}\staticassets that points back to the nuget cache for the files.
i was worried that means your site would somehow be relative, but when you do a dotnet publish ....
it puts everything into the wwwroot of the site under a _content folder
you can also set the base path -
<StaticWebAssetBasePath>App_Plugins/uSync</StaticWebAssetBasePath>
and this means it behaves "Almost" like its really in App_Plugins, (Umbraco still doesn't load the lang xml files, because its not really there, but other stuff looking for a file (e.g a tree node root) now work, because
/App_Plugins/{Plugin}/backoffice/{plugin}
is now a valid path)
s
Just to say I am enjoying this chat, I am not sure what it all means, but I really hope someone will blog it at some point! 😁 Or do a video!
k
yeah - I am writing down some thoughts 🙂 , i am still not 100% sure i understand what it all means too .
s
haha phew glad it's not just me! 😅
p
presumably that's only when debug, if you publish the site the files really would be there
Maybe we can get umbraco to look for plugin assests via the fileproviders they are registering, that way we could read lang files even during debug regardless of if they are in project folder
And a similar trick for finding package.manifests I guess
k
yes - they end up in
wwwroot\App_plugins\uSync
which isn't where they would normally be (
\App_Plugins\uSync
) but from a browser point of view everything works. just the lang files.
@User has some simple code for adding the package manifest (which i've used), but it would be good for it to auto load. if lang folders could be added programatically it would fix it
p
We're having a chat about directory structure next week, and I do hope that App_Plugins will move under wwwroot anyway perhaps with a rename for v10+
but assume there's a workaround for v9
wwwroot/umbraco/plugins seems pretty reasonable
k
I would be concerned about breaking changes in existing packages (i know v10 is breaking, but would be quite nice to have some package stability).
p
That's a valid concern obviously but I think it has to happen at some point, along with fixing the mixed environment files and published files
k
yeah - I would personally vote for - fix all this with the new UI - let the old UI live in its current locations.
p
that sounds fair
for plugins at least, i'd still like to move logs away from config etc
simplify all the gitignores, csprojs, targets etc
on the flip side though, it sounds like it would make RCL easier to utilize for plugin development as wouldn't have to find workarounds for paths
k
yeah - my main concern is reworking existing "already spent a long time reworking packages" only 6 months later 😟 and maintaining the ability to multi-target v8 and v9+ packages (at least until the new UI).
p
yep fatigue is real
k
but yes RCL does look like a really cool opportunity to make the whole process simpler and more 'standard'
p
would it not be quite a small refactor if it's just a base path changing?
k
in some respects yes its faily simple - but it means - new package for v10 that doesn't work on v9, (so branch maintance) and multi-targeting of JS files on v8 they are in one place v9 another
p
Oh and think there will be an RFC for any changes so it's not going to get rushed in without discussion
My understanding is though that because v8 will be around LTS so long, and v9 is up and coming that multi targeting would be more useful
but v10 is a new LTS and no one really should stick on v9
k
in theory 😉 - i get a lot of people asking Qs on a lot of funky versions of Umbraco 7 and 8 - people tend not to upgrade once they are live.
p
I haven't ever really worked on an 8 site, there's so much 7 still about
just pitched in here and there
is it not ok for you to just say, new features v10 only, v7/8/9 is security fixes only?
k
Well we do 😜 , but if your a large multinational 50+ languages connected to some translation service for £100k+ on Umbraco7 your not upgrading any time soon.
(100k is for translation service not us!!!)
p
Sure :p
I guess my thinking here is, v10 is going to be around a long while, and the same discussion will be for vnext after that also, there's not really a good time for things to move
I'd much prefer a stable convention that is documented and lasts forever, right now things are just a bit chaotic on the filesystem
but then I don't have any packages to maintain so it's very easy for me to say 😄
but i suppose you're right that the best time might be new backoffice
k
I suppose transitioning is also an option? Where Umbraco looks in App_Plugins also look in umbraco/plugins then newer packages will all be ready for new structure while older ones continue to work on old versions until the final switch over.?
p
yep
k
Easy for me to say, I'm not a core developer 😃
p
App_plugins is easy to handle, it's just UseStaticFiles(->App_Plugins) + a bit of code to find manifests
don't think it should be too hard to handle two locations
nice thing about a transition instead of a cutover is that could go into 9 though, 9.3 could add support for wwwroot/umbraco/plugins
then i guess that sucks too, writing a 9 plugin which do you pick, hopefully everyone will apply minor and patches more frequently with 9
but maybe it's better to do such things alongside a major 😕
@User pointed out what the Orchard folks are doing which is probably smarter than my msbuild hack in my POC for static assets in core vs downstream project https://github.com/OrchardCMS/OrchardCore/blob/b0c5e2be69689d99b9987e0396d9e8b7ab33b272/src/OrchardCore/OrchardCore/Modules/Extensions/ApplicationBuilderExtensions.cs#L20-L22 Static assets embedded in dll, with physical file provider taking precedence over the embedded provider
j
Not sure how I missed all the fun in this thread!
p
Ignore the bit where I got jealous that you're now the RCL guy :p
2 Views