In this class, we are learning how to create Joomla 2.5 templates by first looking at the PHP code in the Beez2 index.php file. We have already looked at quite a bit of php code, and as we continue our review we come to the following code:

$files = JHtml::_('stylesheet', 'templates/'.$this->template.'/css/general.css', null, false, true);
if ($files):
        if (!is_array($files)):
                $files = array($files);
        foreach($files as $file):
            <link rel="stylesheet" href="/support/<?php echo $file;?>" type="text/css" />


What is the value of $files?

The first line calls JHTML, and we can find out the value of $files by making the following adjustment:

$files = JHtml::_('stylesheet', 'templates/'.$this->template.'/css/general.css', null, false, true);
echo "<pre>"; print_r($files); echo "</pre>"; die();

When we look at the value of $files using the code above, this is what we see:


At this point, we have an absolute URL to our general.css file. We only see one file listed, but the results could have included numerous other css files. What the template now wants to do is include each of these css files. If you see the line starting with foreach, it loops through all the files (such as general.css) and prints them in the following manner:

<link rel="stylesheet" href="/support//templates/beez_20/css/general.css" type="text/css" />


Isn't JHtml suppose to include the CSS file? Why do we loop and print the code ourselves?

If you reviewed the JHtml link we posted above, JHtml was supposed to include the css file on its own, so why didn't it? The entire section of code at the top of this article is in essence simply doing the same exact thing that JHtml could have done for us.

The last flag we passed to JHtml was true, which meant that we only wanted the files returned and not actually printed. If we set the value to false, as in:

$files = JHtml::_('stylesheet', 'templates/'.$this->template.'/css/general.css', null, false, false);

Then we would not have needed to include the rest of the code listed, which actually prints the HTML to include the css.

$files = JHtml::_('stylesheet', 'templates/'.$this->template.'/css/general.css', null, false, false);
if ($files):
        if (!is_array($files)):
                $files = array($files);
        foreach($files as $file):
            <link rel="stylesheet" href="/support/<?php echo $file;?>" type="text/css" />

We hope this makes sense! If you have any questions about this, we're happy to help if you ask us a question in our Community Support area.

Continued Education in Course 219: Joomla 2.5 Template Development Tutorial
You are viewing Section 13: Joomla 2.5 Templates - $files = JHtml::_(stylesheet)
Section 12: How to add a new position to a Joomla 2.5 Template
Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Joomla Community Google+ Hangout #3

June 3rd, 2014

Thank you @RustyJoomla for letting me speak on the Joomla Community Google+ Hangout!

Click here to watch!

Support Center Login

Social Media Login

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Post a Comment

Email Address:
Phone Number:

Please note: Your name and comment will be displayed, but we will not show your email address.

0 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?


Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail:
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!