Open barthamark opened 5 years ago
Options: 1- Replace the view that declares this css, however it could make the BaseTheme feature useless. 2- Redefine a resource registration. But it will also require a custom view. 3- Implement it, but only for css. My only concern is that it should not change the resource manager module, or we should introduce some extensibility that would allow for url substitution, like an event to lookup for a url, and we could return another one if the file exists. This would also mean we need to list all available css from a theme and register them as potential override for resource that have the same name. Which shapes already do.
Feel free to work on something and submit a PR.
@barthamark I came across this looking for another old issue.
This is actually possible currently, due to some vagaries that JT and I have chatted about with the ResourceManager
and how registration works (I have sadly forgotten the details).
However it does work, as I am using it to override the css for a custom admin theme.
The admin theme defines its stylesheet with an inline declaration <style asp-name="admin"/>
If you define a ResourceManifest : IResourceManifestProvider
with a different stylesheet still called admin
it will override the registration.
In my case I imported the admin sass and recompiled it with some tweaks.
You are also able to use a dependency on the existing css, and register it under a different name, to use two stylesheets
That sounds pretty good, thanks! I assume we need to make sure that our resource manifest provider will be executed later than the one we override. The admin
resoure is registered inline which I think is registered first so it seems to be okay, however, how we should make our provider register the resource later than the one we need to override? Startup order maybe?
Here's the original issue where we discussed it with @jtkech https://github.com/OrchardCMS/OrchardCore/issues/5025
Resource versions comment at the bottom look like a useful trick in this scenario as well
So the verdict is to document the override behavior.
This "feature" is quite inconvenient in some cases. We make heavy use of the pro version of Font Awesome 5 and it feels bad to always have to define it with a fake version number just to make sure OrchardCore.Resources doesn't serve us the free one. #1527 seemed like a decent suggestion to get around this issue if you don't want to change the way the ResourceManager handles dependencies.
I don't think the suggestion on https://github.com/OrchardCMS/OrchardCore/issues/1527 would work well, as Override
as a property is too generic.
But your issue @Lawyerson is different to the override technique I suggested here, which works fine if the resource is registered via a tag helper rather than a manifest provider.
What I would suggest, which makes sense for your requirement, i.e. overriding fontawesome, would be to add a Remove
predicate option to the ResourceManifestBuilder
to allow a custom IResourceManifestProvider
to first remove all/some of the font awesome registrations, and then add your own registration for font awesome.
@barthamark I came across this looking for another old issue.
This is actually possible currently, due to some vagaries that JT and I have chatted about with the
ResourceManager
and how registration works (I have sadly forgotten the details).However it does work, as I am using it to override the css for a custom admin theme.
The admin theme defines its stylesheet with an inline declaration
<style asp-name="admin"/>
If you define a
ResourceManifest : IResourceManifestProvider
with a different stylesheet still calledadmin
it will override the registration.In my case I imported the admin sass and recompiled it with some tweaks.
You are also able to use a dependency on the existing css, and register it under a different name, to use two stylesheets
Am I right that I need to create a module (not theme) where override existing resources? I want to override some css and js.
Now ResourceManifest users option pattern so once you have option object you can actually remove/replace previously registers css links using Configure or PostConfigure
Now ResourceManifest users option pattern so once you have option object you can actually remove/replace previously registers css links using Configure or PostConfigure
But I didn't get where I should do put it. Separate module or theme?
You need to register in startup.
it depends, If you have it in theme then it will only have that available when the theme is active
You need to register in startup.
it depends, If you have it in theme then it will only have that available when the theme is active
I have OOTB default blog theme which is a part of nuget package. And I wonder what exactly should I do to override part of that dll If I create separate theme as a project I can't active my own theme because it deactivates blog theme. Where Am I wrong?
May be you are fishing on wrong issue. For themes you can control everything in Layout
if it’s ootb theme, you can override layout using templates or you can create your own theme by keeping ootb theme as base theme
possible solution is also shown here: https://github.com/OrchardCMS/OrchardCore/discussions/12549#discussioncomment-3814218
@lampersky great technique, we need to document how it works.
@ns8482e is also suggesting to add extension methods to ResourceManifest
to easily remove definitions by name.
Duplicate of: https://github.com/OrchardCMS/OrchardCore/issues/1527.
Let's say we have a stylesheet in a module or in a base theme and I want to override it in the default theme. In Orchard 1.x it was possible to create a stylesheet with a similar name - since these technically were shapes it was possible to override them.
Overriding a script is another story - it wasn't possible in Orchard 1.x either.