This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Troiscent
Troiscent

Hello,

I would like to create some independant partials.

For example a slider, I want to create a slider partial, and, when I include it in my page, it would add all required css and js for the slider.

Like that, I don't have to care if my slider have the necessary js and css file, I just embed my partial and it works.

Is it doable with october, if yes, how ?

Thanks

Alex

alxy
alxy

There are the {% scripts %} and and {% styles %} tags.

Troiscent
Troiscent

Not sure it answer my question (or maybe your answer is just a little too short to make me understand) ^^

I need to inject some css and js into the layout when I call my partial.

The {% scripts %} and {% styles %} tags you mention are just to embed your css and js the place you want into your layout. That's not what I'm looking for. I want to inject /assets/js/partial1.js file to my layout when I call {% partial 'partial1.htm' %} for example.

Hope my explaination is clearer now.

Shantarli
Shantarli

alxy gave you two links :) Try 'Injecting' part from both of this: https://octobercms.com/docs/markup/tag-scripts http://octobercms.com/docs/markup/tag-styles

Doc says what particle can contain php code https://octobercms.com/docs/cms/partials#partial-life-cycle Although I am not sure it will work

Troiscent
Troiscent

Ok I see, I can add JS on the onStart method like that :

function onStart()
{
$this->addJs('assets/js/app.js');
}

But I can read on the doc

Links to JavaScript files can be programmatically injected in PHP either by components or pages.

I will try to inject it in my partial but I don't think it will work as the doc precise that it can work for components or pages.

Maybe it's impossible, but it would be great to be able to inject JS with partials directly on the code tab, to not be obliged to write a component to insert in the partial each time you need to inject a small part of js.

Troiscent
Troiscent

Update, it seems you can use onStart() to inject some CSS or JS in partials. Maybe the documentation needs to be updated.

Especially that sentence :

Links to StyleSheet files can be injected in PHP either by components or pages programmatically.

to add partials in the list.

1-6 of 6

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.