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> |
Derek Jones | 733310d | 2009-02-11 01:13:43 +0000 | [diff] [blame] | 31 | <td><h1>CodeIgniter User Guide Version 1.7.1</h1></td> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | |
Derek Allard | 1414987 | 2009-07-22 11:52:09 +0000 | [diff] [blame^] | 63 | <ul> |
| 64 | <li><a href="#br">br()</a></li> |
| 65 | <li><a href="#heading">heading()</a></li> |
| 66 | <li><a href="#img">img()</a></li> |
| 67 | <li><a href="#link_tag">link_tag()</a></li> |
| 68 | <li><a href="#nbs">nbs()</a></li> |
| 69 | <li><a href="#ol_and_ul">ol() and ul()</a></li> |
| 70 | <li><a href="#meta">meta()</a></li> |
| 71 | <li><a href="#doctype">doctype()</a></li> |
| 72 | </ul> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 73 | |
| 74 | <h2>Loading this Helper</h2> |
| 75 | |
| 76 | <p>This helper is loaded using the following code:</p> |
| 77 | <code>$this->load->helper('html');</code> |
| 78 | |
| 79 | <p>The following functions are available:</p> |
| 80 | |
Derek Allard | 1414987 | 2009-07-22 11:52:09 +0000 | [diff] [blame^] | 81 | <h2><a name="br"></a>br()</h2> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 82 | <p>Generates line break tags (<br />) based on the number you submit. Example:</p> |
| 83 | <code>echo br(3);</code> |
| 84 | <p>The above would produce: <br /><br /><br /></p> |
| 85 | |
Derek Allard | 1414987 | 2009-07-22 11:52:09 +0000 | [diff] [blame^] | 86 | <h2><a name="heading"></a>heading()</h2> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 87 | <p>Lets you create HTML <h1> tags. The first parameter will contain the data, the |
| 88 | second the size of the heading. Example:</p> |
| 89 | <code>echo heading('Welcome!', 3);</code> |
| 90 | <p>The above would produce: <h3>Welcome!</h3></p> |
Derek Allard | 1414987 | 2009-07-22 11:52:09 +0000 | [diff] [blame^] | 91 | |
| 92 | <h2><a name="img"></a>img()</h2> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 93 | <p>Lets you create HTML <img /> tags. The first parameter contains the image source. Example:</p> |
| 94 | <code>echo img('images/picture.jpg');<br /> |
| 95 | // gives <img src="http://site.com/images/picture.jpg" /></code> |
| 96 | <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> |
| 97 | <p><code>echo img('images/picture.jpg', TRUE);<br /> |
| 98 | // gives <img src="http://site.com/index.php/images/picture.jpg" /></code></p> |
| 99 | <p>Additionally, an associative array can be passed to the img() function for complete control over all attributes and values.</p> |
| 100 | <p><code> $image_properties = array(<br /> |
| 101 | 'src' => 'images/picture.jpg',<br /> |
| 102 | 'alt' => 'Me, demonstrating how to eat 4 slices of pizza at one time',<br /> |
| 103 | 'class' => 'post_images',<br /> |
| 104 | 'width' => '200',<br /> |
| 105 | 'height' => '200',<br /> |
| 106 | 'title' => 'That was quite a night',<br /> |
| 107 | 'rel' => 'lightbox',<br /> |
| 108 | );<br /> |
| 109 | <br /> |
| 110 | img($image_properties);<br /> |
| 111 | // <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> |
Derek Allard | 1414987 | 2009-07-22 11:52:09 +0000 | [diff] [blame^] | 112 | |
| 113 | <h2><a name="link_tag"></a>link_tag()</h2> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 114 | <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> |
| 115 | echo link_tag('css/mystyles.css');<br /> |
| 116 | // gives <link href="http://site.com/css/mystyles.css" rel="stylesheet" type="text/css" /></code></p> |
| 117 | <p>Further examples:</p> |
| 118 | |
| 119 | <code> |
| 120 | echo link_tag('favicon.ico', 'shortcut icon', 'image/ico');<br /> |
| 121 | // <link href="http://site.com/favicon.ico" rel="shortcut icon" type="image/ico" /> |
| 122 | <br /> |
| 123 | <br /> |
Derek Allard | 7d3773a | 2009-02-04 13:11:56 +0000 | [diff] [blame] | 124 | echo link_tag('feed', 'alternate', 'application/rss+xml', 'My RSS Feed');<br /> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 125 | // <link href="http://site.com/feed" rel="alternate" type="application/rss+xml" title="My RSS Feed" /> </code> |
| 126 | <p>Additionally, an associative array can be passed to the link() function for complete control over all attributes and values.</p> |
| 127 | <p><code> |
| 128 | $link = array(<br /> |
| 129 | 'href' => 'css/printer.css',<br /> |
| 130 | 'rel' => 'stylesheet',<br /> |
| 131 | 'type' => 'text/css',<br /> |
| 132 | 'media' => 'print'<br /> |
| 133 | );<br /> |
| 134 | <br /> |
| 135 | echo link_tag($link);<br /> |
| 136 | // <link href="http://site.com/css/printer.css" rel="stylesheet" type="text/css" media="print" /></code></p> |
| 137 | |
Derek Allard | 1414987 | 2009-07-22 11:52:09 +0000 | [diff] [blame^] | 138 | <h2><a name="nbs"></a>nbs()</h2> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 139 | <p>Generates non-breaking spaces (&nbsp;) based on the number you submit. Example:</p> |
| 140 | <code>echo nbs(3);</code> |
| 141 | <p>The above would produce: &nbsp;&nbsp;&nbsp;</p> |
| 142 | |
Derek Allard | 1414987 | 2009-07-22 11:52:09 +0000 | [diff] [blame^] | 143 | <h2><a name="ol_and_ul"></a>ol() and ul()</h2> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 144 | |
| 145 | <p>Permits you to generate ordered or unordered HTML lists from simple or multi-dimensional arrays. Example:</p> |
| 146 | |
| 147 | <code> |
| 148 | $this->load->helper('html');<br /> |
| 149 | <br /> |
| 150 | $list = array(<br /> |
| 151 | 'red', <br /> |
| 152 | 'blue', <br /> |
| 153 | 'green',<br /> |
| 154 | 'yellow'<br /> |
| 155 | );<br /> |
| 156 | <br /> |
| 157 | $attributes = array(<br /> |
| 158 | 'class' => 'boldlist',<br /> |
| 159 | 'id' => 'mylist'<br /> |
| 160 | );<br /> |
| 161 | <br /> |
| 162 | echo ul($list, $attributes);<br /> |
| 163 | </code> |
| 164 | |
| 165 | <p>The above code will produce this:</p> |
| 166 | |
| 167 | <code> |
| 168 | <ul class="boldlist" id="mylist"><br /> |
| 169 | <li>red</li><br /> |
| 170 | <li>blue</li><br /> |
| 171 | <li>green</li><br /> |
| 172 | <li>yellow</li><br /> |
| 173 | </ul> |
| 174 | </code> |
| 175 | |
| 176 | <p>Here is a more complex example, using a multi-dimensional array:</p> |
| 177 | |
| 178 | <code> |
| 179 | $this->load->helper('html');<br /> |
| 180 | <br /> |
Derek Allard | 904094a | 2009-02-10 14:00:34 +0000 | [diff] [blame] | 181 | $attributes = array(<br /> |
| 182 | 'class' => 'boldlist',<br /> |
| 183 | 'id' => 'mylist'<br /> |
| 184 | );<br /> |
| 185 | <br /> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 186 | $list = array(<br /> |
| 187 | 'colors' => array(<br /> |
| 188 | 'red',<br /> |
| 189 | 'blue',<br /> |
| 190 | 'green'<br /> |
| 191 | ),<br /> |
| 192 | 'shapes' => array(<br /> |
| 193 | 'round', <br /> |
| 194 | 'square',<br /> |
| 195 | 'circles' => array(<br /> |
| 196 | 'ellipse', <br /> |
| 197 | 'oval', <br /> |
| 198 | 'sphere'<br /> |
| 199 | )<br /> |
| 200 | ),<br /> |
| 201 | 'moods' => array(<br /> |
| 202 | 'happy', <br /> |
| 203 | 'upset' => array(<br /> |
| 204 | 'defeated' => array(<br /> |
| 205 | 'dejected',<br /> |
| 206 | 'disheartened',<br /> |
| 207 | 'depressed'<br /> |
| 208 | ),<br /> |
| 209 | 'annoyed',<br /> |
| 210 | 'cross',<br /> |
| 211 | 'angry'<br /> |
| 212 | )<br /> |
| 213 | )<br /> |
| 214 | );<br /> |
| 215 | <br /> |
| 216 | <br /> |
Derek Allard | 904094a | 2009-02-10 14:00:34 +0000 | [diff] [blame] | 217 | echo ul($list, $attributes);</code> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 218 | |
| 219 | <p>The above code will produce this:</p> |
| 220 | |
| 221 | <code> |
| 222 | <ul class="boldlist" id="mylist"><br /> |
| 223 | <li>colors<br /> |
| 224 | <ul><br /> |
| 225 | <li>red</li><br /> |
| 226 | <li>blue</li><br /> |
| 227 | <li>green</li><br /> |
| 228 | </ul><br /> |
| 229 | </li><br /> |
| 230 | <li>shapes<br /> |
| 231 | <ul><br /> |
| 232 | <li>round</li><br /> |
| 233 | <li>suare</li><br /> |
| 234 | <li>circles<br /> |
| 235 | <ul><br /> |
| 236 | <li>elipse</li><br /> |
| 237 | <li>oval</li><br /> |
| 238 | <li>sphere</li><br /> |
| 239 | </ul><br /> |
| 240 | </li><br /> |
| 241 | </ul><br /> |
| 242 | </li><br /> |
| 243 | <li>moods<br /> |
| 244 | <ul><br /> |
| 245 | <li>happy</li><br /> |
| 246 | <li>upset<br /> |
| 247 | <ul><br /> |
| 248 | <li>defeated<br /> |
| 249 | <ul><br /> |
| 250 | <li>dejected</li><br /> |
| 251 | <li>disheartened</li><br /> |
| 252 | <li>depressed</li><br /> |
| 253 | </ul><br /> |
| 254 | </li><br /> |
| 255 | <li>annoyed</li><br /> |
| 256 | <li>cross</li><br /> |
| 257 | <li>angry</li><br /> |
| 258 | </ul><br /> |
| 259 | </li><br /> |
| 260 | </ul><br /> |
| 261 | </li><br /> |
| 262 | </ul> |
| 263 | </code> |
| 264 | |
| 265 | |
| 266 | |
Derek Allard | 1414987 | 2009-07-22 11:52:09 +0000 | [diff] [blame^] | 267 | <h2><a name="meta"></a>meta()</h2> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 268 | |
| 269 | <p>Helps you generate meta tags. You can pass strings to the function, or simple arrays, or multidimensional ones. Examples:</p> |
| 270 | |
| 271 | <code> |
| 272 | echo meta('description', 'My Great site');<br /> |
| 273 | // Generates: <meta name="description" content="My Great Site" /><br /> |
| 274 | <br /><br /> |
| 275 | |
| 276 | echo meta('Content-type', 'text/html; charset=utf-8', 'equiv'); // Note the third parameter. Can be "equiv" or "name"<br /> |
| 277 | // Generates: <meta http-equiv="Content-type" content="text/html; charset=utf-8" /><br /> |
| 278 | |
| 279 | <br /><br /> |
| 280 | |
| 281 | echo meta(array('name' => 'robots', 'content' => 'no-cache'));<br /> |
| 282 | // Generates: <meta name="robots" content="no-cache" /><br /> |
| 283 | |
| 284 | <br /><br /> |
| 285 | |
| 286 | $meta = array(<br /> |
| 287 | array('name' => 'robots', 'content' => 'no-cache'),<br /> |
| 288 | array('name' => 'description', 'content' => 'My Great Site'),<br /> |
| 289 | array('name' => 'keywords', 'content' => 'love, passion, intrigue, deception'),<br /> |
| 290 | array('name' => 'robots', 'content' => 'no-cache'),<br /> |
| 291 | array('name' => 'Content-type', 'content' => 'text/html; charset=utf-8', 'type' => 'equiv')<br /> |
| 292 | );<br /> |
| 293 | <br /> |
| 294 | echo meta($meta); |
| 295 | <br /> |
| 296 | // Generates: <br /> |
| 297 | // <meta name="robots" content="no-cache" /><br /> |
| 298 | // <meta name="description" content="My Great Site" /><br /> |
| 299 | // <meta name="keywords" content="love, passion, intrigue, deception" /><br /> |
| 300 | // <meta name="robots" content="no-cache" /><br /> |
| 301 | // <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> |
| 302 | </code> |
| 303 | |
| 304 | |
Derek Allard | 1414987 | 2009-07-22 11:52:09 +0000 | [diff] [blame^] | 305 | <h2><a name="doctype"></a>doctype()</h2> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 306 | |
| 307 | <p>Helps you generate document type declarations, or DTD's. XHTML 1.0 Strict is used by default, but many doctypes are available.</p> |
| 308 | |
| 309 | <code> |
Derek Allard | 8ab36a5 | 2009-04-14 19:23:10 +0000 | [diff] [blame] | 310 | echo doctype();<br /> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 311 | // <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><br /> |
| 312 | <br /> |
| 313 | echo doctype('html4-trans');<br /> |
| 314 | // <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
| 315 | </code> |
| 316 | |
| 317 | <p>The following is a list of doctype choices. These are configurable, and pulled from <samp>application/config/doctypes.php</samp></p> |
| 318 | |
| 319 | <table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder"> |
| 320 | <tr> |
| 321 | <th>Doctype</th> |
| 322 | <th>Option</th> |
| 323 | <th>Result</th> |
| 324 | </tr> |
| 325 | <tr> |
| 326 | <td class="td">XHTML 1.1</td> |
| 327 | <td class="td">doctype('xhtml11')</td> |
| 328 | <td class="td"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"></td> |
| 329 | </tr> |
| 330 | <tr> |
| 331 | <td class="td">XHTML 1.0 Strict</td> |
| 332 | <td class="td">doctype('xhtml1-strict')</td> |
| 333 | <td class="td"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"></td> |
| 334 | </tr> |
| 335 | <tr> |
| 336 | <td class="td">XHTML 1.0 Transitional</td> |
| 337 | <td class="td">doctype('xhtml1-trans')</td> |
| 338 | <td class="td"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></td> |
| 339 | </tr> |
| 340 | <tr> |
| 341 | <td class="td">XHTML 1.0 Frameset</td> |
| 342 | <td class="td">doctype('xhtml1-frame')</td> |
| 343 | <td class="td"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"></td> |
| 344 | </tr> |
| 345 | <tr> |
| 346 | <td class="td">HTML 5</td> |
| 347 | <td class="td">doctype('html5')</td> |
| 348 | <td class="td"><!DOCTYPE html></td> |
| 349 | </tr> |
| 350 | <tr> |
| 351 | <td class="td">HTML 4 Strict</td> |
| 352 | <td class="td">doctype('html4-strict')</td> |
| 353 | <td class="td"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"></td> |
| 354 | </tr> |
| 355 | <tr> |
| 356 | <td class="td">HTML 4 Transitional</td> |
| 357 | <td class="td">doctype('html4-trans')</td> |
| 358 | <td class="td"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"></td> |
| 359 | </tr> |
| 360 | <tr> |
| 361 | <td class="td">HTML 4 Frameset</td> |
| 362 | <td class="td">doctype('html4-frame')</td> |
| 363 | <td class="td"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"></td> |
| 364 | </tr> |
| 365 | </table> |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | </div> |
| 371 | <!-- END CONTENT --> |
| 372 | |
| 373 | |
| 374 | <div id="footer"> |
| 375 | <p> |
| 376 | Previous Topic: <a href="form_helper.html">Form Helper</a> |
| 377 | · |
| 378 | <a href="#top">Top of Page</a> · |
| 379 | <a href="../index.html">User Guide Home</a> · |
| 380 | Next Topic: <a href="path_helper.html"> Path Helper</a></p> |
Derek Jones | fc395a1 | 2009-04-22 14:15:09 +0000 | [diff] [blame] | 381 | <p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2009 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 382 | </div> |
| 383 | |
| 384 | </body> |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 385 | </html> |