{"id":1593,"date":"2012-07-20T16:19:29","date_gmt":"2012-07-20T16:19:29","guid":{"rendered":"https:\/\/www.inmotionhosting.com\/support\/2012\/07\/20\/files-jhtml\/"},"modified":"2021-08-16T23:39:10","modified_gmt":"2021-08-17T03:39:10","slug":"files-jhtml","status":"publish","type":"post","link":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/","title":{"rendered":"Joomla 2.5 Templates &#8211; $files = JHtml::_(stylesheet)"},"content":{"rendered":"<p>In this class, we are <a href=\"\/support\/website\/working-with-images-in-premium-web-builder\/\">learning how to create Joomla 2.5 templates<\/a> 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:<\/p>\n<pre class=\"code_block\">$files = JHtml::_('stylesheet', 'templates\/'.$this-&gt;template.'\/css\/general.css', null, false, true);\nif ($files):\n        if (!is_array($files)):\n                $files = array($files);\n        endif;\n        foreach($files as $file):\n?&gt;\n            &lt;link rel=\"stylesheet\" href=\"\/support\/&lt;?php echo $file;?&gt;\" type=\"text\/css\" \/&gt;\n&lt;?php\n         endforeach;\nendif;<\/pre>\n<h2>What is the value of $files?<\/h2>\n<p>The first line calls JHTML, and we can find out the value of $files by making the following adjustment:<\/p>\n<pre class=\"code_block\">$files = JHtml::_('stylesheet', 'templates\/'.$this-&gt;template.'\/css\/general.css', null, false, true);\necho \"&lt;pre&gt;\"; print_r($files); echo \"&lt;\/pre&gt;\"; die();<\/pre>\n<p>When we look at the value of $files using the code above, this is what we see:<\/p>\n<pre class=\"code_block\"><strong><span style=\"color: #008000;\">\/templates\/beez_20\/css\/general.css<\/span><\/strong><\/pre>\n<p>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 <strong>foreach<\/strong>, it loops through all the files (such as <em>general.css<\/em>) and prints them in the following manner:<\/p>\n<pre class=\"code_block\">&lt;link rel=\"stylesheet\" href=\"<strong><span style=\"color: #008000;\">\/templates\/beez_20\/css\/general.css<\/span><\/strong>\" type=\"text\/css\" \/&gt;<\/pre>\n<h2>Isn&#8217;t JHtml suppose to include the CSS file? Why do we loop and print the code ourselves?<\/h2>\n<p>If you reviewed the JHtml link we posted above, JHtml was supposed to include the css file on its own, so why didn&#8217;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.<\/p>\n<p>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:<\/p>\n<pre class=\"code_block\">$files = JHtml::_('stylesheet', 'templates\/'.$this-&gt;template.'\/css\/general.css', null, false, false);<\/pre>\n<p>Then we would not have needed to include the rest of the code listed, which actually prints the HTML to include the css.<\/p>\n<pre class=\"code_block\">$files = JHtml::_('stylesheet', 'templates\/'.$this-&gt;template.'\/css\/general.css', null, false, false);\n<del>if ($files):\n        if (!is_array($files)):\n                $files = array($files);\n        endif;\n        foreach($files as $file):\n?&gt;\n            &lt;link rel=\"stylesheet\" href=\"\/support\/&lt;?php echo $file;?&gt;\" type=\"text\/css\" \/&gt;\n&lt;?php\n         endforeach;\nendif;<\/del><\/pre>\n<p>We hope this makes sense! If you have any questions about this, we&#8217;re happy to help if you <a href=\"\/support\/website\/ftp\/configuring-your-site-in-filezilla\/\">ask us a question<\/a> in our Community Support area.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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::_(&#8216;stylesheet&#8217;, &#8216;templates\/&#8217;.$this-&gt;template.&#8217;\/css\/general.css&#8217;, null, false, true); if<a class=\"moretag\" href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/\"> Read More ><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4403,82,4288],"tags":[2113],"class_list":["post-1593","post","type-post","status-publish","format-standard","hentry","category-joomla","category-joomla-2-5","category-website","tag-joomla-v2-5"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Joomla 2.5 Templates - $files = JHtml::_(stylesheet) | InMotion Hosting<\/title>\n<meta name=\"description\" content=\"$files = JHtml::_(stylesheet) is used in our Joomla 2.5 template&#039;s index.php file as a method of loading a css file, general.css\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Joomla 2.5 Templates - $files = JHtml::_(stylesheet) | InMotion Hosting\" \/>\n<meta property=\"og:description\" content=\"$files = JHtml::_(stylesheet) is used in our Joomla 2.5 template&#039;s index.php file as a method of loading a css file, general.css\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/\" \/>\n<meta property=\"og:site_name\" content=\"InMotion Hosting Support Center\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/inmotionhosting\/\" \/>\n<meta property=\"article:published_time\" content=\"2012-07-20T16:19:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-17T03:39:10+00:00\" \/>\n<meta name=\"author\" content=\"Brad Markle\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:site\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Brad Markle\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/\"},\"author\":{\"name\":\"Brad Markle\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/5ae05d1210b0ef63c437ccedce2799bf\"},\"headline\":\"Joomla 2.5 Templates &#8211; $files = JHtml::_(stylesheet)\",\"datePublished\":\"2012-07-20T16:19:29+00:00\",\"dateModified\":\"2021-08-17T03:39:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/\"},\"wordCount\":315,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"keywords\":[\"Joomla v2.5\"],\"articleSection\":[\"Joomla\",\"Joomla 2.5\",\"Website\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/\",\"name\":\"Joomla 2.5 Templates - $files = JHtml::_(stylesheet) | InMotion Hosting\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\"},\"datePublished\":\"2012-07-20T16:19:29+00:00\",\"dateModified\":\"2021-08-17T03:39:10+00:00\",\"description\":\"$files = JHtml::_(stylesheet) is used in our Joomla 2.5 template's index.php file as a method of loading a css file, general.css\",\"breadcrumb\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.inmotionhosting.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Joomla 2.5 Templates &#8211; $files = JHtml::_(stylesheet)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"name\":\"InMotion Hosting Support Center\",\"description\":\"Web Hosting Support &amp; Tutorials\",\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\",\"name\":\"InMotion Hosting\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"contentUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"width\":696,\"height\":696,\"caption\":\"InMotion Hosting\"},\"image\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/inmotionhosting\/\",\"https:\/\/x.com\/InMotionHosting\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/5ae05d1210b0ef63c437ccedce2799bf\",\"name\":\"Brad Markle\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/author\/bradm\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Joomla 2.5 Templates - $files = JHtml::_(stylesheet) | InMotion Hosting","description":"$files = JHtml::_(stylesheet) is used in our Joomla 2.5 template's index.php file as a method of loading a css file, general.css","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/","og_locale":"en_US","og_type":"article","og_title":"Joomla 2.5 Templates - $files = JHtml::_(stylesheet) | InMotion Hosting","og_description":"$files = JHtml::_(stylesheet) is used in our Joomla 2.5 template's index.php file as a method of loading a css file, general.css","og_url":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/","og_site_name":"InMotion Hosting Support Center","article_publisher":"https:\/\/www.facebook.com\/inmotionhosting\/","article_published_time":"2012-07-20T16:19:29+00:00","article_modified_time":"2021-08-17T03:39:10+00:00","author":"Brad Markle","twitter_card":"summary_large_image","twitter_creator":"@InMotionHosting","twitter_site":"@InMotionHosting","twitter_misc":{"Written by":"Brad Markle","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/#article","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/"},"author":{"name":"Brad Markle","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/5ae05d1210b0ef63c437ccedce2799bf"},"headline":"Joomla 2.5 Templates &#8211; $files = JHtml::_(stylesheet)","datePublished":"2012-07-20T16:19:29+00:00","dateModified":"2021-08-17T03:39:10+00:00","mainEntityOfPage":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/"},"wordCount":315,"commentCount":0,"publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"keywords":["Joomla v2.5"],"articleSection":["Joomla","Joomla 2.5","Website"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/","url":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/","name":"Joomla 2.5 Templates - $files = JHtml::_(stylesheet) | InMotion Hosting","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#website"},"datePublished":"2012-07-20T16:19:29+00:00","dateModified":"2021-08-17T03:39:10+00:00","description":"$files = JHtml::_(stylesheet) is used in our Joomla 2.5 template's index.php file as a method of loading a css file, general.css","breadcrumb":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-2-5\/files-jhtml\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.inmotionhosting.com\/support\/"},{"@type":"ListItem","position":2,"name":"Joomla 2.5 Templates &#8211; $files = JHtml::_(stylesheet)"}]},{"@type":"WebSite","@id":"https:\/\/www.inmotionhosting.com\/support\/#website","url":"https:\/\/www.inmotionhosting.com\/support\/","name":"InMotion Hosting Support Center","description":"Web Hosting Support &amp; Tutorials","publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.inmotionhosting.com\/support\/#organization","name":"InMotion Hosting","url":"https:\/\/www.inmotionhosting.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","contentUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","width":696,"height":696,"caption":"InMotion Hosting"},"image":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/inmotionhosting\/","https:\/\/x.com\/InMotionHosting"]},{"@type":"Person","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/5ae05d1210b0ef63c437ccedce2799bf","name":"Brad Markle","url":"https:\/\/www.inmotionhosting.com\/support\/author\/bradm\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"primary_category":null,"_links":{"self":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/1593","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/comments?post=1593"}],"version-history":[{"count":4,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/1593\/revisions"}],"predecessor-version":[{"id":85800,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/1593\/revisions\/85800"}],"wp:attachment":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/media?parent=1593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/categories?post=1593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/tags?post=1593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}