Welcome Guest, Not a member yet? Register   Sign In
Header Library v2.0
#1

[eluser]textnotspeech[/eluser]
This is an update to a library a wrote a while ago for automatically populating <head> content. The new version is much more detached and portable and offers some slick new features (if I do say so myself). Basically the library populates an array of variables to pass to a view containing your <head> content. It allows you to set the page title and/or body id with minimal code in view while also dynamically adding all your stylesheets, javascripts, meta tags and doctype information. The new version utilizes the Google AJAX library API to include your favorite AJAX libraries like jQuery or Prototype. It also includes some extended browser detection functionality that can be used to dynamically add browser-specific stylesheets (great for IE styles without conditional comments). It also detects iPhone/iPod Touch devices and will automatically write header tags for the iPhone layout ratio and the shortcut icon. This class is a small, simple but super useful library to make configuring your <head> content easy as pie. The header object allows you to dynamically add and configure your header content through a simple API for each specific page (if you're in need of that kind of thing; which I find useful for things like adding TinyMCE editor to specific pages).

The code an documentation can be found at my website here: http://daytonnolan.com/header-library-v2...-extension

UPDATE: This library works great with this simple template library: http://ellislab.com/forums/viewthread/99892/
#2

[eluser]RaF007[/eluser]
Looks nice, think I'll be using it for upcoming projects. Thanks!

One question though: if I understand well, since you didn't opt for using a config file for default values, we have to repeat global css/js files in each controller?
#3

[eluser]textnotspeech[/eluser]
No. The javascript and stylesheet defaults are set using the constructor.
#4

[eluser]RaF007[/eluser]
[quote author="textnotspeech" date="1233155243"]No. The javascript and stylesheet defaults are set using the constructor.[/quote]

But which constructor? In each controller's constructor, right?
-
(sorry - probably asking dumb questions, I don't have much experience with CodeIgniter yet)
#5

[eluser]textnotspeech[/eluser]
No. You set the defaults in the header.php library constructor. Like so:
Code:
public function __construct()
        {            
            $this->doctype = 'Strict'; // Set the Doctype definition
            $this->title = "Default title"; // Set the default page title
            $this->body_id = ""; // Set the default body id (leave blank for no id)
            $this->icon_path = "images/icons/"; // Set default icon path for iPhone relative base_url().
            $this->css_path = "css/"; // Set default path to browser specific css files relative to base_url().
            $this->safari_css = FALSE; // Safari specific stylesheet
            $this->opera_css = FALSE; // Opera specific stylesheet
            $this->iphone_css = TRUE; // iPhone specific stylesheet
            $this->stylesheets = array('default' => 'default.css'); // Set a default stylesheet
            $this->javascript_path = 'javascript/'; // Set path to javascripts
            $this->ajax_lib = array("library" => "jQueryUI",
                                    "version" => "1.2.6,1.5.3"
                                   );
            $this->javascripts = array('custom_javascript' => 'javascript.js');
            $this->keywords = 'Keyword 1, Keyword 2';
            $this->http_meta_tags = array('Content-Type' => 'text/html; charset=utf-8');
            $this->content_meta_tags = array('description' => 'This is the meta description of mysite',
                                             'keywords' => $this->keywords,
                                             'author' => 'Your Name',
                                             'generator' => 'Code Igniter'
                                            );
        } // End __construct function

Just change the values to the desired values in the constructor.
#6

[eluser]textnotspeech[/eluser]
CSS files and Javascripts are an in arrays with a label as a key (which is optional I suppose) and the filename as the value. The path to the respective files is set using $this->css_path and $this->javascript_path




Theme © iAndrew 2016 - Forum software by © MyBB