1084

Helper to load external libraries and stylesheets

Comments for “Helper to load external libraries and stylesheets”
 

Posted by DaddyJohn on Thursday 24th February 2022 at 13:02 GMT

I am sure I saw a Trongate helper function that enabled you to load libraries / stylesheets easily into the Head, but I cannot for the life of me find it.

Can anyone point me to the right place.

Thanks
Early Adopter

DaddyJohn

User Level: Early Adopter

Date Joined: 23/01/2022

Posted by djnordeen on Thursday 24th February 2022 at 13:21 GMT

Hello DaddyJohn,
First, In your other questions that you asked, if someone has given you a correct answer to your question, Could you please click the Star in the upper right corner to close out the thread.
Thanks

Regard to your question.
CSS files. There is not a helper. Calling the css file depends on its location.
For example, If you create a module, keep all relevant files in the module, like the assets/css folder. Because this will enable you to copy and paste the module into any app.

I have taken phpMailer and made a module out of it. It take alot of trial and error to get the file structure working right.

There are no Helpers for libraries. That said, It depends on the library you want to load.
Can you share what library? Or is this just a general question?

Dan

This comment was edited by djnordeen on Thursday 24th February 2022 at 13:25 GMT

Early Adopter

djnordeen

User Level: Early Adopter

Date Joined: 20/08/2021

Posted by Davcon on Thursday 24th February 2022 at 14:30 GMT

I think I know what you mean. It's not really a library. It's just a case of loading an array of stuff into the template.

If you have a look at how the 'admin' template is put together, you'll see this in action. In particular, have a look for 'additional_includes_top'. Hopefully that will be helpful.
Founding Member

Davcon

User Level: Founding Member

Date Joined: 3/11/2018

Posted by DaddyJohn on Thursday 24th February 2022 at 14:56 GMT

Thanks DC, you are right, I was thinking of $additional_includes_top which I just found.

The reason why I was looking for it, is that I am working through the Goldmine tutorial. When I got to Lesson 18 I had to refactor the form in add_to_cart to change the closing form tags to echo form_close();

This solved one problem, but now when store_items/display/ is loading, I am getting issues with the stylesheet loading with a console message of DevTools failed to load source map: Could not load content for http://localhost/goldmine/css/defiant.css.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

I thought perhaps loading defiant css via $additional_includes_top might help, but I dont hold out much hope.

This comment was edited by DaddyJohn on Thursday 24th February 2022 at 14:57 GMT

Early Adopter

DaddyJohn

User Level: Early Adopter

Date Joined: 23/01/2022

Posted by D3mon on Thursday 24th February 2022 at 15:21 GMT

Try removing this line from defiant.css:

/*# sourceMappingURL=defiant.css.map */
Level One Member

D3mon

User Level: Level One Member

Date Joined: 6/07/2021

Posted by DaddyJohn on Thursday 24th February 2022 at 15:33 GMT

I already had removed this.
Early Adopter

DaddyJohn

User Level: Early Adopter

Date Joined: 23/01/2022

Posted by D3mon on Thursday 24th February 2022 at 15:38 GMT

It is useful to have a helper to add in custom stylesheets/scripts on a per-page basis but it does mean the you have to hand over some control of the 'head' element of the output back to the framework, which may be undesirable.

As a work around, in your controller, add to the view data a small array of the HTML attributes of the link, for example a stylesheet:

$data['extraStylesheets'] = [
    [
        'rel' => 'stylesheet',
        'href' => '...path/to/style1.css'
    ],
    [ 
        'rel' => 'stylesheet',
        'href => '...path/to/style2.css'
    ]
]


Then in your view, you can loop through 'extraStylesheets' and reconstruct the HTML tags in the head section of your output.

(I had trouble posting the code to reconstruct them here - sorry.)

This comment was edited by D3mon on Thursday 24th February 2022 at 15:48 GMT

Level One Member

D3mon

User Level: Level One Member

Date Joined: 6/07/2021

Posted by D3mon on Thursday 24th February 2022 at 15:50 GMT

Your browser may be caching the request for the css.map file in that case. Maybe a hard refresh will clear the console error.
Level One Member

D3mon

User Level: Level One Member

Date Joined: 6/07/2021

Posted by Davcon on Thursday 24th February 2022 at 16:15 GMT

Whatever it is, it's a two minute fix.

Call me up when you're on Skype and get ready to share your screen.
Founding Member

Davcon

User Level: Founding Member

Date Joined: 3/11/2018

×