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?

4
  • "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? Commented May 28, 2023 at 7: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 :-) Commented May 28, 2023 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 Commented Jun 13, 2023 at 9:11
  • Thank you, Simon. Please post your comment as the answer. That will work for me. Commented Jun 14, 2023 at 14:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.