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">
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 <title>HTML Helper : CodeIgniter User Guide</title>
8 <style type='text/css' media='all'>@import url('../userguide.css');</style>
9 <link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
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>
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' />
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>
29 <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
31 <td><h1>CodeIgniter User Guide Version 2.0.2</h1></td>
32 <td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
36 <!-- END NAVIGATION -->
39 <!-- START BREADCRUMB -->
40 <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
43 <a href="http://codeigniter.com/">CodeIgniter Home</a> ›
44 <a href="../index.html">User Guide Home</a> ›
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>
50 <!-- END BREADCRUMB -->
55 <!-- START CONTENT -->
61 <p>The HTML Helper file contains functions that assist in working with HTML.</p>
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>
74 <h2>Loading this Helper</h2>
76 <p>This helper is loaded using the following code:</p>
77 <code>$this->load->helper('html');</code>
79 <p>The following functions are available:</p>
81 <h2><a name="br"></a>br()</h2>
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>
86 <h2><a name="heading"></a>heading()</h2>
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>
92 <h2><a name="img"></a>img()</h2>
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" alt="" /></code></p>
99 <p>Additionally, an associative array can be passed to the img() function for complete control over all attributes and values. If an alt attribute is not provided, CodeIgniter will generate an empty string.</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 />
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>
113 <h2><a name="link_tag"></a>link_tag()</h2>
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>
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" />
124 echo link_tag('feed', 'alternate', 'application/rss+xml', 'My RSS Feed');<br />
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>
129 'href' => 'css/printer.css',<br />
130 'rel' => 'stylesheet',<br />
131 'type' => 'text/css',<br />
132 'media' => 'print'<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>
138 <h2><a name="nbs"></a>nbs()</h2>
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>
143 <h2><a name="ol_and_ul"></a>ol() and ul()</h2>
145 <p>Permits you to generate ordered or unordered HTML lists from simple or multi-dimensional arrays. Example:</p>
148 $this->load->helper('html');<br />
151 'red', <br />
152 'blue', <br />
153 'green',<br />
154 'yellow'<br />
155 );<br />
157 $attributes = array(<br />
158 'class' => 'boldlist',<br />
159 'id' => 'mylist'<br />
160 );<br />
162 echo ul($list, $attributes);<br />
165 <p>The above code will produce this:</p>
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 />
176 <p>Here is a more complex example, using a multi-dimensional array:</p>
179 $this->load->helper('html');<br />
181 $attributes = array(<br />
182 'class' => 'boldlist',<br />
183 'id' => 'mylist'<br />
184 );<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 />
217 echo ul($list, $attributes);</code>
219 <p>The above code will produce this:</p>
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 />
267 <h2><a name="meta"></a>meta()</h2>
269 <p>Helps you generate meta tags. You can pass strings to the function, or simple arrays, or multidimensional ones. Examples:</p>
272 echo meta('description', 'My Great site');<br />
273 // Generates: <meta name="description" content="My Great Site" /><br />
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 />
281 echo meta(array('name' => 'robots', 'content' => 'no-cache'));<br />
282 // Generates: <meta name="robots" content="no-cache" /><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 />
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" />
305 <h2><a name="doctype"></a>doctype()</h2>
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>
310 echo doctype();<br />
311 // <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><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">
317 <p>The following is a list of doctype choices. These are configurable, and pulled from <samp>application/config/doctypes.php</samp></p>
319 <table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
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>
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>
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>
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>
346 <td class="td">HTML 5</td>
347 <td class="td">doctype('html5')</td>
348 <td class="td"><!DOCTYPE html></td>
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>
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>
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>
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>
381 <p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006 - 2011 · <a href="http://ellislab.com/">EllisLab, Inc.</a></p>