adding styles

Be informed that this forum is not an official support forum for Joomla! 4.0. Any issues regarding Joomla! 4.0 must be reported at https://issues.joomla.org/.

Joomla! 4.0 is still in its Alpha stage. This forum should be used for sharing information about Joomla! 4.0.

Moderator: ooffick

Post Reply
erick-b
Joomla! Intern
Joomla! Intern
Posts: 81
Joined: Tue Feb 17, 2015 10:25 am

adding styles

Post by erick-b » Mon Mar 11, 2019 2:50 pm

Hi
with these tags I can add metas , styles and scripts to <head> tag

Code: Select all

<jdoc:include type="metas" />
<jdoc:include type="styles" />
<jdoc:include type="scripts" />
but how do I add the css files into jdoc:include type="styles" ? where is this include ?


thanks

User avatar
pmleconte
Joomla! Explorer
Joomla! Explorer
Posts: 369
Joined: Fri Mar 17, 2017 12:55 pm
Location: France

Re: adding styles

Post by pmleconte » Mon Mar 11, 2019 4:21 pm

Hi,

We already had a long discussion about this : viewtopic.php?f=803&t=968305

Pascal
If anything can go wrong, it will.
https://www.conseilgouz.com/en

erick-b
Joomla! Intern
Joomla! Intern
Posts: 81
Joined: Tue Feb 17, 2015 10:25 am

Re: adding styles

Post by erick-b » Mon Mar 11, 2019 4:37 pm

thanks

that's terrible to read with no clear answer
ill remove the iclude tag for styles and them in my way

for now I cannot se any gain with J4.0

User avatar
pmleconte
Joomla! Explorer
Joomla! Explorer
Posts: 369
Joined: Fri Mar 17, 2017 12:55 pm
Location: France

Re: adding styles

Post by pmleconte » Mon Mar 11, 2019 5:59 pm

What are you looking for ?

If you need to add your own CSS files, it can be done through joomla.assets.json.
If you just need to add some CSS commands, just add then in user.css file.

Pascal
If anything can go wrong, it will.
https://www.conseilgouz.com/en

erick-b
Joomla! Intern
Joomla! Intern
Posts: 81
Joined: Tue Feb 17, 2015 10:25 am

Re: adding styles

Post by erick-b » Mon Mar 11, 2019 6:01 pm

I have tried to add it with joomla.assets.json, it does not work
it was so simple with joomla 3.x

User avatar
pmleconte
Joomla! Explorer
Joomla! Explorer
Posts: 369
Joined: Fri Mar 17, 2017 12:55 pm
Location: France

Re: adding styles

Post by pmleconte » Mon Mar 11, 2019 6:04 pm

What are you trying to add in joomla.assets.json file ? CSS files ?
If anything can go wrong, it will.
https://www.conseilgouz.com/en

erick-b
Joomla! Intern
Joomla! Intern
Posts: 81
Joined: Tue Feb 17, 2015 10:25 am

Re: adding styles

Post by erick-b » Mon Mar 11, 2019 6:08 pm

joomla.asset.json

Code: Select all

{
  "name": "ymages",
  "version": "4.0.0",
  "description": "Ymages template",
  "license": "GPL-2.0+",
  "assets": {   
    "template.ymages": {
      "name": "template.ymages",
      "dependencies": ["template.ymages"],
      "css": [
        "ymages.css"
      ]
  }
}}
in my index.php

Code: Select all

use Joomla\CMS\HTML\HTMLHelper;
$wa   = $this->getWebAssetManager(); 
$wa->enableAsset('template.ymages');

JHtml::_('stylesheet', 'ymages.css', false, true);

<jdoc:include type="styles" />
there is no rtl , ltr or base , my template is ymages for all

THANKS

erick-b
Joomla! Intern
Joomla! Intern
Posts: 81
Joined: Tue Feb 17, 2015 10:25 am

Re: adding styles

Post by erick-b » Mon Mar 11, 2019 6:17 pm

$doc->addStyleSheet($tpath . '/css/ymages.css');

works perfectly , and only one line

User avatar
pmleconte
Joomla! Explorer
Joomla! Explorer
Posts: 369
Joined: Fri Mar 17, 2017 12:55 pm
Location: France

Re: adding styles

Post by pmleconte » Mon Mar 11, 2019 7:51 pm

To understand the "Why" and "How", please check https://issues.joomla.org/tracker/joomla-cms/22435

You just have 2 lines to make json file work :

Code: Select all

$wa   = $this->getWebAssetManager(); 
$wa->enableAsset('template.ymages');
then, you create your json file and it's done.

I'm not sure if it is safer to update a json file instead of your index.php file each time you have something to add.

Pascal
If anything can go wrong, it will.
https://www.conseilgouz.com/en

erick-b
Joomla! Intern
Joomla! Intern
Posts: 81
Joined: Tue Feb 17, 2015 10:25 am

Re: adding styles

Post by erick-b » Mon Mar 11, 2019 8:09 pm

Thank you Pascal but it does not work , the css file is not loaded

User avatar
sozzled
Joomla! Champion
Joomla! Champion
Posts: 7197
Joined: Sun Jul 05, 2009 3:30 am
Location: Canberra, Australia
Contact:

Re: adding styles

Post by sozzled » Mon Mar 11, 2019 8:17 pm

There are other ways to add a stylesheet to a J! template. One way is to use a plugin—a plugin that allows you to use [almost] any CSS file that you upload to your website and does the "heavy lifting" for you. There are plugins that people have written—if you look at the JED—that might do what you're trying to achieve. 8)

Using a plugin means that you do not need to make changes to a template or to J! when you update the template or update J!

It's just an idea. Good luck. :)
https://www.kuneze.com/blog
Former member of Kunena project team
If you think I’m wrong then say “I think you're wrong.” If you say “You’re wrong!”, how do you know?

erick-b
Joomla! Intern
Joomla! Intern
Posts: 81
Joined: Tue Feb 17, 2015 10:25 am

Re: adding styles

Post by erick-b » Mon Mar 11, 2019 10:31 pm

no needs for a plugin to do that
$doc->addStyleSheet($tpath . '/css/ymages.css'); works very well

I just wanted to try the new J4 way but it seems to be absurd

thanks to all

SharkyKZ
Joomla! Ace
Joomla! Ace
Posts: 1567
Joined: Fri Jul 05, 2013 10:35 am
Location: Unknown

Re: adding styles

Post by SharkyKZ » Tue Mar 12, 2019 7:43 am

In your JSON file you added the asset as its own dependency which is of course wrong. Remove the dependency and it works fine:

Code: Select all

{
  "name": "ymages",
  "version": "4.0.0",
  "description": "Ymages template",
  "license": "GPL-2.0+",
  "assets": {   
    "template.ymages": {
      "name": "template.ymages",
      "css": [
        "ymages.css"
      ]
  }
}}

erick-b
Joomla! Intern
Joomla! Intern
Posts: 81
Joined: Tue Feb 17, 2015 10:25 am

Re: adding styles

Post by erick-b » Tue Mar 12, 2019 1:19 pm

thanks now it works

but it is anyway much more complicated than before for what reason ? what gain ?


Post Reply

Return to “Joomla! 4 Related”