Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame^] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 2 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| 3 | <head> |
| 4 | |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 6 | <title>HTML Helper : CodeIgniter User Guide</title> |
| 7 | |
| 8 | <style type='text/css' media='all'>@import url('../userguide.css');</style> |
| 9 | <link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> |
| 10 | |
| 11 | <script type="text/javascript" src="../nav/nav.js"></script> |
| 12 | <script type="text/javascript" src="../nav/prototype.lite.js"></script> |
| 13 | <script type="text/javascript" src="../nav/moo.fx.js"></script> |
| 14 | <script type="text/javascript" src="../nav/user_guide_menu.js"></script> |
| 15 | |
| 16 | <meta http-equiv='expires' content='-1' /> |
| 17 | <meta http-equiv= 'pragma' content='no-cache' /> |
| 18 | <meta name='robots' content='all' /> |
| 19 | <meta name='author' content='ExpressionEngine Dev Team' /> |
| 20 | <meta name='description' content='CodeIgniter User Guide' /> |
| 21 | |
| 22 | </head> |
| 23 | <body> |
| 24 | |
| 25 | <!-- START NAVIGATION --> |
| 26 | <div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> |
| 27 | <div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> |
| 28 | <div id="masthead"> |
| 29 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%"> |
| 30 | <tr> |
| 31 | <td><h1>CodeIgniter User Guide Version 1.7</h1></td> |
| 32 | <td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> |
| 33 | </tr> |
| 34 | </table> |
| 35 | </div> |
| 36 | <!-- END NAVIGATION --> |
| 37 | |
| 38 | |
| 39 | <!-- START BREADCRUMB --> |
| 40 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%"> |
| 41 | <tr> |
| 42 | <td id="breadcrumb"> |
| 43 | <a href="http://codeigniter.com/">CodeIgniter Home</a> › |
| 44 | <a href="../index.html">User Guide Home</a> › |
| 45 | HTML Helper |
| 46 | </td> |
| 47 | <td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> |
| 48 | </tr> |
| 49 | </table> |
| 50 | <!-- END BREADCRUMB --> |
| 51 | |
| 52 | <br clear="all" /> |
| 53 | |
| 54 | |
| 55 | <!-- START CONTENT --> |
| 56 | <div id="content"> |
| 57 | |
| 58 | |
| 59 | <h1>HTML Helper</h1> |
| 60 | |
| 61 | <p>The HTML Helper file contains functions that assist in working with HTML.</p> |
| 62 | |
| 63 | |
| 64 | <h2>Loading this Helper</h2> |
| 65 | |
| 66 | <p>This helper is loaded using the following code:</p> |
| 67 | <code>$this->load->helper('html');</code> |
| 68 | |
| 69 | <p>The following functions are available:</p> |
| 70 | |
| 71 | <h2>br()</h2> |
| 72 | <p>Generates line break tags (<br />) based on the number you submit. Example:</p> |
| 73 | <code>echo br(3);</code> |
| 74 | <p>The above would produce: <br /><br /><br /></p> |
| 75 | |
| 76 | <h2>heading()</h2> |
| 77 | <p>Lets you create HTML <h1> tags. The first parameter will contain the data, the |
| 78 | second the size of the heading. Example:</p> |
| 79 | <code>echo heading('Welcome!', 3);</code> |
| 80 | <p>The above would produce: <h3>Welcome!</h3></p> |
| 81 | <h2>img()</h2> |
| 82 | <p>Lets you create HTML <img /> tags. The first parameter contains the image source. Example:</p> |
| 83 | <code>echo img('images/picture.jpg');<br /> |
| 84 | // gives <img src="http://site.com/images/picture.jpg" /></code> |
| 85 | <p>There is an optional second parameter that is a TRUE/FALSE value that specifics if the src should have the page specified by $config['index_page'] added to the address it creates. Presumably, this would be if you were using a media controller.</p> |
| 86 | <p><code>echo img('images/picture.jpg', TRUE);<br /> |
| 87 | // gives <img src="http://site.com/index.php/images/picture.jpg" /></code></p> |
| 88 | <p>Additionally, an associative array can be passed to the img() function for complete control over all attributes and values.</p> |
| 89 | <p><code> $image_properties = array(<br /> |
| 90 | 'src' => 'images/picture.jpg',<br /> |
| 91 | 'alt' => 'Me, demonstrating how to eat 4 slices of pizza at one time',<br /> |
| 92 | 'class' => 'post_images',<br /> |
| 93 | 'width' => '200',<br /> |
| 94 | 'height' => '200',<br /> |
| 95 | 'title' => 'That was quite a night',<br /> |
| 96 | 'rel' => 'lightbox',<br /> |
| 97 | );<br /> |
| 98 | <br /> |
| 99 | img($image_properties);<br /> |
| 100 | // <img src="http://site.com/index.php/images/picture.jpg" alt="Me, demonstrating how to eat 4 slices of pizza at one time" class="post_images" width="200" height="200" title="That was quite a night" rel="lightbox" /></code></p> |
| 101 | <h2>link_tag()</h2> |
| 102 | <p>Lets you create HTML <link /> tags. This is useful for stylesheet links, as well as other links. The parameters are href, with optional rel, type, title, media and index_page. index_page is a TRUE/FALSE value that specifics if the href should have the page specified by $config['index_page'] added to the address it creates.<code> |
| 103 | echo link_tag('css/mystyles.css');<br /> |
| 104 | // gives <link href="http://site.com/css/mystyles.css" rel="stylesheet" type="text/css" /></code></p> |
| 105 | <p>Further examples:</p> |
| 106 | |
| 107 | <code> |
| 108 | echo link_tag('favicon.ico', 'shortcut icon', 'image/ico');<br /> |
| 109 | // <link href="http://site.com/favicon.ico" rel="shortcut icon" type="image/ico" /> |
| 110 | <br /> |
| 111 | <br /> |
| 112 | echo link('feed', 'alternate', 'application/rss+xml', 'My RSS Feed');<br /> |
| 113 | // <link href="http://site.com/feed" rel="alternate" type="application/rss+xml" title="My RSS Feed" /> </code> |
| 114 | <p>Additionally, an associative array can be passed to the link() function for complete control over all attributes and values.</p> |
| 115 | <p><code> |
| 116 | $link = array(<br /> |
| 117 | 'href' => 'css/printer.css',<br /> |
| 118 | 'rel' => 'stylesheet',<br /> |
| 119 | 'type' => 'text/css',<br /> |
| 120 | 'media' => 'print'<br /> |
| 121 | );<br /> |
| 122 | <br /> |
| 123 | echo link_tag($link);<br /> |
| 124 | // <link href="http://site.com/css/printer.css" rel="stylesheet" type="text/css" media="print" /></code></p> |
| 125 | |
| 126 | <h2>nbs()</h2> |
| 127 | <p>Generates non-breaking spaces (&nbsp;) based on the number you submit. Example:</p> |
| 128 | <code>echo nbs(3);</code> |
| 129 | <p>The above would produce: &nbsp;&nbsp;&nbsp;</p> |
| 130 | |
| 131 | <h2>ol() and ul()</h2> |
| 132 | |
| 133 | <p>Permits you to generate ordered or unordered HTML lists from simple or multi-dimensional arrays. Example:</p> |
| 134 | |
| 135 | <code> |
| 136 | $this->load->helper('html');<br /> |
| 137 | <br /> |
| 138 | $list = array(<br /> |
| 139 | 'red', <br /> |
| 140 | 'blue', <br /> |
| 141 | 'green',<br /> |
| 142 | 'yellow'<br /> |
| 143 | );<br /> |
| 144 | <br /> |
| 145 | $attributes = array(<br /> |
| 146 | 'class' => 'boldlist',<br /> |
| 147 | 'id' => 'mylist'<br /> |
| 148 | );<br /> |
| 149 | <br /> |
| 150 | echo ul($list, $attributes);<br /> |
| 151 | </code> |
| 152 | |
| 153 | <p>The above code will produce this:</p> |
| 154 | |
| 155 | <code> |
| 156 | <ul class="boldlist" id="mylist"><br /> |
| 157 | <li>red</li><br /> |
| 158 | <li>blue</li><br /> |
| 159 | <li>green</li><br /> |
| 160 | <li>yellow</li><br /> |
| 161 | </ul> |
| 162 | </code> |
| 163 | |
| 164 | <p>Here is a more complex example, using a multi-dimensional array:</p> |
| 165 | |
| 166 | <code> |
| 167 | $this->load->helper('html');<br /> |
| 168 | <br /> |
| 169 | $list = array(<br /> |
| 170 | 'colors' => array(<br /> |
| 171 | 'red',<br /> |
| 172 | 'blue',<br /> |
| 173 | 'green'<br /> |
| 174 | ),<br /> |
| 175 | 'shapes' => array(<br /> |
| 176 | 'round', <br /> |
| 177 | 'square',<br /> |
| 178 | 'circles' => array(<br /> |
| 179 | 'ellipse', <br /> |
| 180 | 'oval', <br /> |
| 181 | 'sphere'<br /> |
| 182 | )<br /> |
| 183 | ),<br /> |
| 184 | 'moods' => array(<br /> |
| 185 | 'happy', <br /> |
| 186 | 'upset' => array(<br /> |
| 187 | 'defeated' => array(<br /> |
| 188 | 'dejected',<br /> |
| 189 | 'disheartened',<br /> |
| 190 | 'depressed'<br /> |
| 191 | ),<br /> |
| 192 | 'annoyed',<br /> |
| 193 | 'cross',<br /> |
| 194 | 'angry'<br /> |
| 195 | )<br /> |
| 196 | )<br /> |
| 197 | );<br /> |
| 198 | <br /> |
| 199 | <br /> |
| 200 | echo ul($list);</code> |
| 201 | |
| 202 | <p>The above code will produce this:</p> |
| 203 | |
| 204 | <code> |
| 205 | <ul class="boldlist" id="mylist"><br /> |
| 206 | <li>colors<br /> |
| 207 | <ul><br /> |
| 208 | <li>red</li><br /> |
| 209 | <li>blue</li><br /> |
| 210 | <li>green</li><br /> |
| 211 | </ul><br /> |
| 212 | </li><br /> |
| 213 | <li>shapes<br /> |
| 214 | <ul><br /> |
| 215 | <li>round</li><br /> |
| 216 | <li>suare</li><br /> |
| 217 | <li>circles<br /> |
| 218 | <ul><br /> |
| 219 | <li>elipse</li><br /> |
| 220 | <li>oval</li><br /> |
| 221 | <li>sphere</li><br /> |
| 222 | </ul><br /> |
| 223 | </li><br /> |
| 224 | </ul><br /> |
| 225 | </li><br /> |
| 226 | <li>moods<br /> |
| 227 | <ul><br /> |
| 228 | <li>happy</li><br /> |
| 229 | <li>upset<br /> |
| 230 | <ul><br /> |
| 231 | <li>defeated<br /> |
| 232 | <ul><br /> |
| 233 | <li>dejected</li><br /> |
| 234 | <li>disheartened</li><br /> |
| 235 | <li>depressed</li><br /> |
| 236 | </ul><br /> |
| 237 | </li><br /> |
| 238 | <li>annoyed</li><br /> |
| 239 | <li>cross</li><br /> |
| 240 | <li>angry</li><br /> |
| 241 | </ul><br /> |
| 242 | </li><br /> |
| 243 | </ul><br /> |
| 244 | </li><br /> |
| 245 | </ul> |
| 246 | </code> |
| 247 | |
| 248 | |
| 249 | |
| 250 | <h2>meta()</h2> |
| 251 | |
| 252 | <p>Helps you generate meta tags. You can pass strings to the function, or simple arrays, or multidimensional ones. Examples:</p> |
| 253 | |
| 254 | <code> |
| 255 | echo meta('description', 'My Great site');<br /> |
| 256 | // Generates: <meta name="description" content="My Great Site" /><br /> |
| 257 | <br /><br /> |
| 258 | |
| 259 | echo meta('Content-type', 'text/html; charset=utf-8', 'equiv'); // Note the third parameter. Can be "equiv" or "name"<br /> |
| 260 | // Generates: <meta http-equiv="Content-type" content="text/html; charset=utf-8" /><br /> |
| 261 | |
| 262 | <br /><br /> |
| 263 | |
| 264 | echo meta(array('name' => 'robots', 'content' => 'no-cache'));<br /> |
| 265 | // Generates: <meta name="robots" content="no-cache" /><br /> |
| 266 | |
| 267 | <br /><br /> |
| 268 | |
| 269 | $meta = array(<br /> |
| 270 | array('name' => 'robots', 'content' => 'no-cache'),<br /> |
| 271 | array('name' => 'description', 'content' => 'My Great Site'),<br /> |
| 272 | array('name' => 'keywords', 'content' => 'love, passion, intrigue, deception'),<br /> |
| 273 | array('name' => 'robots', 'content' => 'no-cache'),<br /> |
| 274 | array('name' => 'Content-type', 'content' => 'text/html; charset=utf-8', 'type' => 'equiv')<br /> |
| 275 | );<br /> |
| 276 | <br /> |
| 277 | echo meta($meta); |
| 278 | <br /> |
| 279 | // Generates: <br /> |
| 280 | // <meta name="robots" content="no-cache" /><br /> |
| 281 | // <meta name="description" content="My Great Site" /><br /> |
| 282 | // <meta name="keywords" content="love, passion, intrigue, deception" /><br /> |
| 283 | // <meta name="robots" content="no-cache" /><br /> |
| 284 | // <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> |
| 285 | </code> |
| 286 | |
| 287 | |
| 288 | <h2>doctype()</h2> |
| 289 | |
| 290 | <p>Helps you generate document type declarations, or DTD's. XHTML 1.0 Strict is used by default, but many doctypes are available.</p> |
| 291 | |
| 292 | <code> |
| 293 | echo docytype();<br /> |
| 294 | // <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><br /> |
| 295 | <br /> |
| 296 | echo doctype('html4-trans');<br /> |
| 297 | // <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
| 298 | </code> |
| 299 | |
| 300 | <p>The following is a list of doctype choices. These are configurable, and pulled from <samp>application/config/doctypes.php</samp></p> |
| 301 | |
| 302 | <table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder"> |
| 303 | <tr> |
| 304 | <th>Doctype</th> |
| 305 | <th>Option</th> |
| 306 | <th>Result</th> |
| 307 | </tr> |
| 308 | <tr> |
| 309 | <td class="td">XHTML 1.1</td> |
| 310 | <td class="td">doctype('xhtml11')</td> |
| 311 | <td class="td"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"></td> |
| 312 | </tr> |
| 313 | <tr> |
| 314 | <td class="td">XHTML 1.0 Strict</td> |
| 315 | <td class="td">doctype('xhtml1-strict')</td> |
| 316 | <td class="td"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"></td> |
| 317 | </tr> |
| 318 | <tr> |
| 319 | <td class="td">XHTML 1.0 Transitional</td> |
| 320 | <td class="td">doctype('xhtml1-trans')</td> |
| 321 | <td class="td"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></td> |
| 322 | </tr> |
| 323 | <tr> |
| 324 | <td class="td">XHTML 1.0 Frameset</td> |
| 325 | <td class="td">doctype('xhtml1-frame')</td> |
| 326 | <td class="td"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"></td> |
| 327 | </tr> |
| 328 | <tr> |
| 329 | <td class="td">HTML 5</td> |
| 330 | <td class="td">doctype('html5')</td> |
| 331 | <td class="td"><!DOCTYPE html></td> |
| 332 | </tr> |
| 333 | <tr> |
| 334 | <td class="td">HTML 4 Strict</td> |
| 335 | <td class="td">doctype('html4-strict')</td> |
| 336 | <td class="td"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"></td> |
| 337 | </tr> |
| 338 | <tr> |
| 339 | <td class="td">HTML 4 Transitional</td> |
| 340 | <td class="td">doctype('html4-trans')</td> |
| 341 | <td class="td"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"></td> |
| 342 | </tr> |
| 343 | <tr> |
| 344 | <td class="td">HTML 4 Frameset</td> |
| 345 | <td class="td">doctype('html4-frame')</td> |
| 346 | <td class="td"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"></td> |
| 347 | </tr> |
| 348 | </table> |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | </div> |
| 354 | <!-- END CONTENT --> |
| 355 | |
| 356 | |
| 357 | <div id="footer"> |
| 358 | <p> |
| 359 | Previous Topic: <a href="form_helper.html">Form Helper</a> |
| 360 | · |
| 361 | <a href="#top">Top of Page</a> · |
| 362 | <a href="../index.html">User Guide Home</a> · |
| 363 | Next Topic: <a href="path_helper.html"> Path Helper</a></p> |
| 364 | <p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> |
| 365 | </div> |
| 366 | |
| 367 | </body> |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 368 | </html> |