0

I am starting out with CodeIgniter 4 and am using https://github.com/noraziz/ci4-twiggy as my template engine.

The documentation is pretty sparce, but so far it is working, with the exception that I am unable to load a custom CSS file when it is not in the public folder.

So - setting my CSS file to

<link rel="stylesheet" href="main.css" />

loads the file, as it then default looks in the public folder. Setting it thus to:

<link rel="stylesheet" href="../app/Themes/mytheme/assets/css/main.css" />

I was expecting that I would be able to load it, but I am not. It keeps giving me a 404 error. This user had a similar issue, How can I load css or js file in codeigniter 4?, however, his files were located in the public folder, and was not using Twig, so the solution did not work for me either.

I had several other attempts (including removing the app/.htaccess file temporarily):

{{ base_url() }}app/Themes/mytheme/assets/css/main.css

app/Themes/mytheme/assets/css/main.css

Themes/mytheme/assets/css/main.css    

mytheme/assets/css/main.css

assets/css/main.css

css/main.css

main.css  (after removing the file from **public** folder, of course)

Since the template engine is not in the public folder, I do not want to move my CSS to the public folder, unless there is no other way without compromising security. Is there?

Kobus Myburgh
  • 1,114
  • 1
  • 17
  • 46
  • "*I do not want to move my CSS to the public folder*" - Then how do you expect browsers to actually download/serve the CSS file? – DarkBee May 28 '23 at 07:49
  • Well, I was hoping to not have to split my actual theme file and its assets for ease of maintenance. I hoped there was a way to make that available. For now I have implemented it in the public folder, and it works. I was just hoping it was not necessary :-) – Kobus Myburgh May 28 '23 at 12:56
  • 1
    If you don't want to split the files, you could use a bundler(webpack etc) to serve a combined css-file into the public folder with the partial files sitting somewhere else – Simon Weber Jun 13 '23 at 09:11
  • Thank you, Simon. Please post your comment as the answer. That will work for me. – Kobus Myburgh Jun 14 '23 at 14:01

0 Answers0