Welcome Guest, Not a member yet? Register   Sign In
Create /public folder in a theme
#1

Hello !

I use CodeIgniter 4 and I want to create 2 themes (front & back) who will be located to the root folder.

Each theme will have his JavaScript and CSS files. So I don't want to put this files in the default public folder, but I want to have a public folder in each theme.

Is it possible to do that ? Currently, I can't access directly to the public folder inside the theme.

I want a strcuture like that :

- /app
---- /Config
---- /Controllers
---- ...
- /public
---- index.php
---- .htaccess
---- ...
- /themes
---- /back
------- /public
---------- /css
---------- /js
------- / Views
---------- Login.php
---- /front
------- /public
---------- /css
---------- /js
------- /Views
---------- Homepage.php

Thank you !
Reply
#2

(This post was last modified: 12-20-2019, 06:01 AM by MGatner.)

Everything web accessible needs to be in public/. You could put your folders as you have it and then symlink them, but if public/ is your serve root (which it should be) then only files in there are reachable by the browser.

Aside, you might want to check out this theme module that makes it easy to save and switch themes:

https://github.com/tattersoftware/codeigniter4-themes

The other option if you absolutely need to have your files outside of public/ is to use a media server. I’m not sure if that is a good idea for core theme files though, performance wise.
Reply
#3

Thank you for your answer.

Yes, public/ is my serve root.

I already looked this project. Maybe I didn't understand how it works, but the complete theme folder is inside the public folder, so all my views are accessible via the URL no ?

I thought about cdn but I prefer to avoid this solution.

Currently, I have my views inside my themes/ folder, and all css, js, img in a subfolder inside public/. It works but it's not a good solution I found.

Else, I search to use .htaccess but without success for now.
Reply
#4

I don't know if it is a good solition, but maybe I can create a controller who will load the css, js and img files?

In the Routes file, I redirect all the files beginig by /themes/ to the controller, and the controller load the source?

I try something like that, but each time I have an extension in the URL, I'm redirecting to the default controller, and not to my controller. I don't know why...
Reply
#5

Understood! Yes I haven't thought of an implementation that has view files in addition to assets. You could embed your assets inline as views, but that wouldn't work for images (unless you wanted to base64 them on-the-fly, probably not a great solution). Maybe also check out what @lonnieezell is doing here:
https://github.com/lonnieezell/myth-forums

He has themes in the root with a webpack definition to publish them out to public/.
Reply
#6

Hello, thank you for your answer. I don't know yet if this solution will suit me, but I will make some tests and see what that gives. I think that is a good solution for js and css files, but not for images also.

I will continue the research. If someone knows a solution or a lead, do not hesitate to report it! Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB