{"id":232,"date":"2011-09-29T13:32:05","date_gmt":"2011-09-29T11:32:05","guid":{"rendered":"http:\/\/demianlabs.com\/lab\/?p=232"},"modified":"2013-08-25T16:36:34","modified_gmt":"2013-08-25T14:36:34","slug":"templates-themes-for-codeigniter","status":"publish","type":"post","link":"https:\/\/demianlabs.com\/lab\/post\/templates-themes-for-codeigniter\/","title":{"rendered":"Templates &#038; themes for CodeIgniter"},"content":{"rendered":"<p>One of the biggest drawbacks of a framework is the absence of built in theming functionality. CodeIgniter is no exception to that rule. Although there are quite a few libraries out there which aim to provide theming support, they don&#8217;t feel like being part of the framework. I was annoyed with having to use anything which looks like an ugly hack so I created a library which supports themes in CodeIgniter in a native style.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-236\" title=\"Templates for CodeIgniter\" alt=\"Templates for CodeIgniter\" src=\"https:\/\/demianlabs.com\/lab\/wp-content\/uploads\/templates.jpg\" width=\"482\" height=\"239\" srcset=\"https:\/\/demianlabs.com\/lab\/wp-content\/uploads\/templates.jpg 482w, https:\/\/demianlabs.com\/lab\/wp-content\/uploads\/templates-300x148.jpg 300w\" sizes=\"auto, (max-width: 482px) 100vw, 482px\" \/><\/p>\n<p><strong>First of all let&#8217;s see how this baby works:<\/strong><\/p>\n<p>Using themes:<\/p>\n<pre>$this-&gt;load-&gt;theme('demo');\r\n$this-&gt;load-&gt;view('home');<\/pre>\n<p>Loading CSS and Javascript files from within your views:<\/p>\n<pre>$this-&gt;load-&gt;css('\/themes\/demo\/css\/styles.css');\r\n$this-&gt;load-&gt;js('\/themes\/demo\/js\/javascript.js');<\/pre>\n<p>Yes that was all. It is that simple.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Structure of your files<\/strong><\/p>\n<p>In the same path as your <em>application<\/em> folder create a <em>theme<\/em> folder and inside it a folder with the theme&#8217;s name. Also create a folder with the theme&#8217;s name inside <em>views<\/em>.<\/p>\n<p>Inside the download you will see how the <em>demo<\/em> theme is structured.<\/p>\n<pre>\/application\/views\/demo\/...    (Your views go here)\r\n\/themes\/demo\/css\/...           (CSS files)\r\n\/themes\/demo\/js\/...            (Javascript files)\r\n\/themes\/demo\/theme.php         (The theme file itself)<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Bonus: Caching control<\/strong><\/p>\n<p>Have you noticed that sometimes when you update your css or javascript files the changes don&#8217;t take effect until the browser empties it&#8217;s cache ? This library supports a suffix for all css and javascript files which allows you to control the caching of your files by the browser. Inside the config folder you will find a file mainframe.php. Make sure you autoload it and set a version for your files.<\/p>\n<pre>$config['cjsuf'] = '0.1';<\/pre>\n<p>When you change that version to say 0.2, browsers will be forced to reload them since they think it is a different file.<\/p>\n<p>&nbsp;<\/p>\n<p>Inside the download there is a demo theme to get you started<\/p>\n<p><strong><a title=\"Templates &amp; themes for CodeIgniter\" href=\"https:\/\/demianlabs.com\/lab\/wp-content\/uploads\/Themable codeigniter 0.2.zip\">Download it here<\/a><\/strong><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the biggest drawbacks of a framework is the absence of built in theming functionality. CodeIgniter is no exception to that rule. Although there are quite a few libraries out there which aim to provide theming support, they don&#8217;t feel like being part of the framework. I was annoyed with having to use anything [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-232","post","type-post","status-publish","format-standard","hentry","category-academy"],"_links":{"self":[{"href":"https:\/\/demianlabs.com\/lab\/wp-json\/wp\/v2\/posts\/232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demianlabs.com\/lab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/demianlabs.com\/lab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/demianlabs.com\/lab\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demianlabs.com\/lab\/wp-json\/wp\/v2\/comments?post=232"}],"version-history":[{"count":18,"href":"https:\/\/demianlabs.com\/lab\/wp-json\/wp\/v2\/posts\/232\/revisions"}],"predecessor-version":[{"id":250,"href":"https:\/\/demianlabs.com\/lab\/wp-json\/wp\/v2\/posts\/232\/revisions\/250"}],"wp:attachment":[{"href":"https:\/\/demianlabs.com\/lab\/wp-json\/wp\/v2\/media?parent=232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/demianlabs.com\/lab\/wp-json\/wp\/v2\/categories?post=232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demianlabs.com\/lab\/wp-json\/wp\/v2\/tags?post=232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}