GetSimple Support Forum

Full Version: Injecting css / js into <head>
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

trying to figure out how to inject (easy way) for some pages specific css or js.

I know I can do this with different templates but it's much more work and especially when I use 1 same layout.

I would appreciate any suggestion 'how to' (again - easy way) or some specific plugin that could do this?

Thanx

Alex
inject from where, what is the context ?

A plugin ? where ? Front end, back end ?
Shawn,

just from the CMS / Admin .. let's say it could be one extra input field within "Page Options".

Something like 'Custom page Title' plug-in .. it lays on the bottom of the Page Options (when open) just as a input field.

Why? to prevent large css file, overrides .. and custom js only where necessary.

Alex
I think 'injecting' is a wrong term, it should be "adding more css file's, js .." inside the head of html

Alex
You want to add custom css or js for specific pages ?

You could clone your template files, and include those assets, and then change the template on the pages you need them in.

or add a custom field to flag it and then in your template conditionally include them.

Now if you need lots of different combinations then your way is probably the best, you will need a plugin made for it or hack your own strings togather with special page templates or whatnot.

I am not aware of a plugin made for what you are asking. Definitely a good idea.
Shawn,

I did try once 'Custom fields' plugin for the same reason but something went wrong .. can not remember now.

I could give it a shot once again just to check it if it gonna work.

This idea came from working with the grids / blocks, sass / scss, mixins .. so having a possibility to add more css / js file's into the template trough the Page Options could lighten (long/big) loaded files, shorten developing time ..

Building a front-end with ooscc/smacss/dry method gives me the possibility for less (practically just one) php template, shorter main css and few custom (page dedicated) css chunks.
Also changing the layout for one page could go just trough one chunk of dedicated css file. Without hurting the rest ..

And ,. I'm not gonna start 'hacking strings ..' ;-) and such, i'm just a IxD/WD/FeD

Thanx for reply

Alex
I barely know what any of that means.

There is another plugin called "simple input tabs" that might be worth checking into
You can use components to insert code into the <head> I have only done it with a few lines of css or to turn on and off the robots "no follow" thing. Can't get easier than that.
Yeah i thought about using components and hooks to load other components, this way ytuor block are editable as components and reusable, which you cannot do with page options.

So you would have components do different groups of stuff.

and then you could use dynpages to laod these inline in pages ( probably not rpeffered for large styles or js )
alternativly you would use a hook ( my component hook plugin ) to load other components in head or footer depending on the current slug or some special field.

I have never tested fetchign a component from inside a component.
ok gentleman's .. M Vlcek's "i18n-custom-fields" works good for adding css / js file's within <head>

It's just enough so I think it's not necessary to develop a separate plugin for this purpose.

Thanx for responses ;-)

Alex