Doctype Plugin |
[eluser]Adam Griffiths[/eluser]
I recently made this plugin to display a doctype easily. This should be saved as doctype_pi.php in your application/plugins/ folder and loaded like... Code: $this->load->plugin('doctype'); Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Usage You can display both HTML and xHTML doctpyes using this funtion. Pass the HTML type to the first function, and the doctype you want to use (strict, transitional, frameset). The default will be xHTML Strict. It's small, but it sure does help me a lot! It's easier to type out doctype(); than <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">. It's probably not the best I could've done, I could've done it differently. But it works and is quite useful to myself, so I thought I'd share. Thanks.
[eluser]Randy Casburn[/eluser]
Sweet man! Nice. One of those "why didn't I think of that! Thanks Adam. Randy
[eluser]xwero[/eluser]
Personally i like the syntax of OP in this thread more. Because it leaves the door open for other doctypes. And why not use a config file for the different doctypes? Code: // config (config/doctypes.php)
[eluser]Adam Griffiths[/eluser]
Thanks guys. @xwero: You don't need to just put doctype();, by all means if it helps you can put doctype('xhtml', 'strict'); I didn't use a config file because I don't think it warrants one, it's just a small function and is by no means a be all and end all solution for everyone. It serves a purpose and if any newer doctpyes are released, I will update it. :-)
[eluser]xwero[/eluser]
Now the people have two ways of adding the doctype. Personally i don't like your error messages they don't belong in a professional environment. There are more doctype than you added and you don't know which doctype someone needs so instead of updating it yourself or let a developer alter the plugin himself putting the doctypes in a config file is the most flexible way to generate the html output. Also you code is too complex for such a easy generation. If another $lang is needed it requires another elseif around line 30. Keep your code as compact and flexible as possible that is what i'm trying to point out.
[eluser]Adam Griffiths[/eluser]
Ok, so I made another version, it's more like yours but you don't need to echo the function. doctype_pi.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); config/doctypes.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Usage Code: <?php doctype('xhtml-strict'); ?> or Code: <?=doctype('xhtml-strict');?> As before, xHTML and HTML Strict, Tranisitional and Frameset are supported. Oh and @my error messages, there is no way on earth that they would be shown to the user in the file I gave, it was just a bit of fun. I used it in a project with another developer and it made us both laugh. It was just a quick knockup of a function we needed to have.
[eluser]axpen[/eluser]
Great idea, I was wondering if anyone did this with CodeIgniter, good job. Also just a note for people that don't already know, just a doctype alone doesn't make a valid XHTML page, it must come after <?xml version="1.0" encoding="iso-8859-1"?> or such and followed by a <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">. |
Welcome Guest, Not a member yet? Register Sign In |