Insert js and css files in head in certain pages only ?

This forum is for general questions about extensions for Joomla! 3.x.

Moderators: pe7er, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
FrancoisRJoom
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Wed Oct 21, 2015 12:54 pm

Insert js and css files in head in certain pages only ?

Post by FrancoisRJoom » Mon Jan 25, 2016 12:48 pm

Hello everyone,

I must insert css and javascript files only in a few pages of my website and not others not in all of them
These css and js files should be in the <head> section just before the closing tag</head>
Do you know if there is a secured and updated extension to do that with the last version of joomla ?
If not, is there an other solution ?

I am absolutely ok to pay for that. I would even feel more confident with a commercial extension

I thank you already and I am looking forward impatiently your advises

François

User avatar
brian
Joomla! Master
Joomla! Master
Posts: 12787
Joined: Fri Aug 12, 2005 7:19 am
Location: Leeds, UK
Contact:

Re: Insert js and css files in head in certain pages only ?

Post by brian » Mon Jan 25, 2016 12:50 pm

"Exploited yesterday... Hacked tomorrow"
Blog http://brian.teeman.net/
Joomla Hidden Secrets http://hiddenjoomlasecrets.com/

FrancoisRJoom
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Wed Oct 21, 2015 12:54 pm

Re: Insert js and css files in head in certain pages only ?

Post by FrancoisRJoom » Mon Jan 25, 2016 12:59 pm

Great, thanks Brian. It seems to be what I need. However the design of there website isn't that reassuring. Can I trust them on security ? Do you think they update this extension often ? Do you have other suggestions ?

User avatar
brian
Joomla! Master
Joomla! Master
Posts: 12787
Joined: Fri Aug 12, 2005 7:19 am
Location: Leeds, UK
Contact:

Re: Insert js and css files in head in certain pages only ?

Post by brian » Mon Jan 25, 2016 1:10 pm

Developers are rarely good at design. But if you look Viktor Vogel is on the core Joomla production leadership team :)
"Exploited yesterday... Hacked tomorrow"
Blog http://brian.teeman.net/
Joomla Hidden Secrets http://hiddenjoomlasecrets.com/

dude808
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sat Dec 07, 2013 7:38 am

Re: Insert js and css files in head in certain pages only ?

Post by dude808 » Mon Jan 25, 2016 2:53 pm

Hi @FrancoisRJoom,

I can vouch for Viktor Vogel. I find him to be one of the most reliable, dedicated, and friendliest Joomla! developers on this planet.

I have posted several tweets about him and his extensions on a number of occasions.

But if you do not want to take my word for it, ask around, or even better contact him directly (https://twitter.com/viktorvogel) I'm sure he would gladly address all of your concerns.

Regards,

Joe Campbell
https://twitter.com/heyjoecampbell

User avatar
leolam
Joomla! Master
Joomla! Master
Posts: 20652
Joined: Mon Aug 29, 2005 10:17 am
Location: Netherlands/ Germany/ S'pore/Bogor/ North America
Contact:

Re: Insert js and css files in head in certain pages only ?

Post by leolam » Mon Jan 25, 2016 4:26 pm

I can concur to what Brian stated. This plugin works like a charm and I am very happy to receive guidance from Victor in The Joomla Bug Squad. He is a very professional developer and a tremendous Joomla contributor.

Leo 8)
Joomla's #1 Professional Services Provider:
#Joomla Professional Support: https://gws-desk.com -
#Joomla Specialized Hosting Solutions: https://gws-host.com -

FrancoisRJoom
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Wed Oct 21, 2015 12:54 pm

Re: Insert js and css files in head in certain pages only ?

Post by FrancoisRJoom » Mon Feb 01, 2016 2:11 pm

Great thank you all. I am changing the tatus of this post to "resolved"
I will follow your advices and let you know how happy I ll be.

FrancoisRJoom
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Wed Oct 21, 2015 12:54 pm

Re: Insert js and css files in head in certain pages only ?

Post by FrancoisRJoom » Wed Feb 03, 2016 1:26 pm

Hi,

I tested the Victor Vogel plugin "JS CSS Control". Unfortunaltly it doesn't do what I want.

It suppresses loading jss and css files on pages where they are not needed.
But what I need is to load js and css files on the pageswhere they are needed.

The difference my seem subtile but it changes everything.
I cannot list 198 pages among 200 where a css file is not needed.

Any other recommandation ?

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30923
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Insert js and css files in head in certain pages only ?

Post by Per Yngve Berg » Thu Feb 04, 2016 2:35 pm

Set a Page Class Suffix in the Menu items and use php code in the head section in your template to load the css.

FrancoisRJoom
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Wed Oct 21, 2015 12:54 pm

Re: Insert js and css files in head in certain pages only ?

Post by FrancoisRJoom » Thu Feb 04, 2016 2:42 pm

Interesting Per Yngve Berg,
lets say my Page Class Suffix is "page_insurance"
and my css style sheet is located there templates/mytemplate/css/page_insurance.css
what would be the php code I should write ?

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30923
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Insert js and css files in head in certain pages only ?

Post by Per Yngve Berg » Thu Feb 04, 2016 9:16 pm

Code: Select all

<?php
$app             = JFactory::getApplication();
$doc             = JFactory::getDocument();
$itemid   = $app->input->getCmd('Itemid', '');
$menu     = $app->getMenu();
$menuParams = $menu->getParams($itemid);
$pageclass  = $menuParams['pageclass_sfx'];
// Add Stylesheets
$doc->addStyleSheet($this->baseurl . '/templates/' . $this->template . '/css/'.$pageclass.'.css');
?>

User avatar
AlexVega
Joomla! Hero
Joomla! Hero
Posts: 2711
Joined: Fri Aug 28, 2015 6:13 am
Location: México

Re: Insert js and css files in head in certain pages only ?

Post by AlexVega » Tue Feb 09, 2016 6:42 am

Hi there,

Also you can try with this extension:
http://extensions.joomla.org/extensions ... pt-control

Cheers!

FrancoisRJoom
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Wed Oct 21, 2015 12:54 pm

Re: Insert js and css files in head in certain pages only ?

Post by FrancoisRJoom » Mon Sep 26, 2016 10:07 am

Hi i'm coming back here to tell you what I finally do to insert css and js files in the page I want and not the others.
I use the excellent extension sourcerer by regular labs.
It's by far the simplest extension I tried so far and the most complete. It works on modules also etc. Peter the developper is very helpful he is reliable on the regular updates.
Once you installed the extension you place this code in an article :

Code: Select all

{source}
<?php
   $doc->addScriptDeclaration( $script );
   $doc->addScript( JURI::root( true ).'templates/mytemplate/js/myjsfile.js' ); 
   $doc->addStyleDeclaration( $css );
   $doc->addStyleSheet( JURI::root( true ).'templates/mytemplate/css/mycss.css' ); 
?>
{/source}

semmel
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Wed Dec 10, 2014 10:11 am

Re: Insert js and css files in head in certain pages only ?

Post by semmel » Thu Oct 20, 2016 6:37 pm

It looks like the JS CSS Control now can include files, not only exclude. I can exclude files, but can not get include to work. I select "Yes" in "Toggle - Flip Execution Limitation" but no file is included.
Any tip?
Thanks

semmel
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Wed Dec 10, 2014 10:11 am

Re: Insert js and css files in head in certain pages only ?

Post by semmel » Sat Oct 22, 2016 9:00 am

Oh it should be "JCC - JS CSS Control" not JS CSS Control. Link

FrancoisRJoom
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Wed Oct 21, 2015 12:54 pm

Re: Insert js and css files in head in certain pages only ?

Post by FrancoisRJoom » Tue Dec 27, 2016 11:02 pm

hey i m back here to let you know tht the sourcerer extension is the best one i tried its free and works very well


Locked

Return to “Extensions for Joomla! 3.x”