Try our conversational search powered by Generative AI!

Access to static content in /modules/MyPlugin in CMS 12?

Vote:
 

Hi!

I'm rewriting a plugin from CMS 11 to CMS 12 and in CMS 11 the module was places in /modules/MyPlugin/.
I that folder we have some img, js and css under /modules/MyPlugin/ClientResources/css/my.css or /modules/MyPlugin/ClientResources/img/myimage.jpg for example.

In CMS 11 I could just use the URL https://localhost:1234/modules/MyPlugin/ClientResources/img/myimage.jpg and the image would render but if I use the same URL now if just get a 404.

I have views in /modules/MyPlugin/Views/ that I can access and they are rendered and it is these views that contains links to the static content above.

What do I need to do to have access to the static content in my plugin folder?

Thanks!

/Kristoffer

#267915
Dec 06, 2021 10:25
Vote:
 

Hi!

So this actually solved the problem.

app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider(
        Path.Combine(env.ContentRootPath, "modules", "MyPlugin", "ClientResources")),
    RequestPath = "/modules/MyPlugin/ClientResources"
});

Is this the correct way of doing it?

Thanks!

/Kristoffer

#267973
Dec 07, 2021 13:02
Vote:
 

More info here:

https://world.optimizely.com/blogs/kristoffer-linden/dates/2021/12/how-to-initialize-your-custom-plugin/

#268435
Dec 15, 2021 21:46
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.