blob: 17c28cd2a8b253b9d9f277cdc93e377ec3491df9 [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001###########
2HTML Helper
3###########
4
5The HTML Helper file contains functions that assist in working with
6HTML.
7
8.. contents:: Page Contents
9
10Loading this Helper
11===================
12
13This helper is loaded using the following code::
14
15 $this->load->helper('html');
16
17The following functions are available:
18
19br()
20====
21
22Generates line break tags (<br />) based on the number you submit.
23Example::
24
25 echo br(3);
26
27The above would produce: <br /><br /><br />
28
29heading()
30=========
31
32Lets you create HTML <h1> tags. The first parameter will contain the
33data, the second the size of the heading. Example::
34
35 echo heading('Welcome!', 3);
36
37The above would produce: <h3>Welcome!</h3>
38
39Additionally, in order to add attributes to the heading tag such as HTML
40classes, ids or inline styles, a third parameter is available.
41
42::
43
44 echo heading('Welcome!', 3, 'class="pink"')
45
46The above code produces: <h3 class="pink">Welcome!<<h3>
47
48img()
49=====
50
51Lets you create HTML <img /> tags. The first parameter contains the
52image source. Example
53
54::
55
56 echo img('images/picture.jpg'); // gives <img src="http://site.com/images/picture.jpg" />
57
58There is an optional second parameter that is a TRUE/FALSE value that
59specifics if the src should have the page specified by
60$config['index_page'] added to the address it creates. Presumably, this
61would be if you were using a media controller.
62
63::
64
65 echo img('images/picture.jpg', TRUE); // gives <img src="http://site.com/index.php/images/picture.jpg" alt="" />
66
67
68Additionally, an associative array can be passed to the img() function
69for complete control over all attributes and values. If an alt attribute
70is not provided, CodeIgniter will generate an empty string.
71
72::
73
74 $image_properties = array(           
75 'src' => 'images/picture.jpg',           
76 'alt' => 'Me, demonstrating how to eat 4 slices of pizza at one time',  
77 'class' => 'post_images',           
78 'width' => '200',           
79 'height'=> '200',           
80 'title' => 'That was quite a night',           
81 'rel' => 'lightbox'
82 );
83
84 img($image_properties); // <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" />
85
86
87link_tag()
88===========
89
90Lets you create HTML <link /> tags. This is useful for stylesheet links,
91as well as other links. The parameters are href, with optional rel,
92type, title, media and index_page. index_page is a TRUE/FALSE value
93that specifics if the href should have the page specified by
94$config['index_page'] added to the address it creates.
95
96::
97
98 echo link_tag('css/mystyles.css'); // gives <link href="http://site.com/css/mystyles.css" rel="stylesheet" type="text/css" />
99
100
101Further examples
102
103::
104
105 echo link_tag('favicon.ico', 'shortcut icon', 'image/ico'); // <link href="http://site.com/favicon.ico" rel="shortcut icon" type="image/ico" />
106
107 echo link_tag('feed', 'alternate', 'application/rss+xml', 'My RSS Feed'); // <link href="http://site.com/feed" rel="alternate" type="application/rss+xml" title="My RSS Feed" />
108
109Additionally, an associative array can be passed to the link() function
110for complete control over all attributes and values.
111
112::
113
114 $link = array(           
115 'href' => 'css/printer.css',           
116 'rel' => 'stylesheet',           
117 'type' => 'text/css',           
118 'media' => 'print'
119 );
120
121 echo link_tag($link); // <link href="http://site.com/css/printer.css" rel="stylesheet" type="text/css" media="print" />
122
123
124nbs()
125=====
126
127Generates non-breaking spaces (&nbsp;) based on the number you submit.
128Example
129
130::
131
132 echo nbs(3);
133
134The above would produce
135
136::
137
138 &nbsp;&nbsp;&nbsp;
139
140ol() and ul()
141=============
142
143Permits you to generate ordered or unordered HTML lists from simple or
144multi-dimensional arrays. Example
145
146::
147
148 $this->load->helper('html');
149
150 $list = array(             
151 'red',             
152 'blue',             
153 'green',             
154 'yellow'             
155 );
156
157 $attributes = array(                     
158 'class' => 'boldlist',                     
159 'id'    => 'mylist'                    
160 );
161
162 echo ul($list, $attributes);
163
164The above code will produce this
165
166::
167
168 <ul class="boldlist" id="mylist">   
169 <li>red</li>   
170 <li>blue</li>   
171 <li>green</li>   
172 <li>yellow</li>
173 </ul>
174
175Here is a more complex example, using a multi-dimensional array
176
177::
178
179 $this->load->helper('html');
180
181 $attributes = array(                     
182 'class' => 'boldlist',                     
183 'id'    => 'mylist'                     
184 );
185
186 $list = array(             
187 'colors' => array(                                 
188 'red',                                 
189 'blue',                                 
190 'green'                             
191 ),
192 'shapes' => array(                                 
193 'round',                                 
194 'square',                                 
195 'circles' => array(                                             
196 'ellipse',
197 'oval',
198 'sphere'
199 )                             
200 ),             
201 'moods' => array(                                 
202 'happy',                                 
203 'upset' => array                                        
204 'defeated' => array(
205 'dejected',                
206 'disheartened',
207 'depressed'
208 ),
209 'annoyed',
210 'cross',
211 'angry'
212 )
213 )
214 );
215
216 echo ul($list, $attributes);
217
218The above code will produce this
219
220::
221
222 <ul class="boldlist" id="mylist">   
223 <li>colors     
224 <ul>       
225 <li>red</li>       
226 <li>blue</li>       
227 <li>green</li>     
228 </ul>   
229 </li>   
230 <li>shapes     
231 <ul>       
232 <li>round</li>       
233 <li>suare</li>       
234 <li>circles         
235 <ul>           
236 <li>elipse</li>           
237 <li>oval</li>           
238 <li>sphere</li>         
239 </ul>       
240 </li>     
241 </ul>   
242 </li>   
243 <li>moods     
244 <ul>       
245 <li>happy</li>       
246 <li>upset         
247 <ul>           
248 <li>defeated             
249 <ul>               
250 <li>dejected</li>
251 <li>disheartened</li>
252 <li>depressed</li>
253 </ul>
254 </li>
255 <li>annoyed</li>
256 <li>cross</li>           
257 <li>angry</li>         
258 </ul>       
259 </li>     
260 </ul>   
261 </li>
262 </ul>
263
264meta()
265======
266
267Helps you generate meta tags. You can pass strings to the function, or
268simple arrays, or multidimensional ones. Examples
269
270::
271
272 echo meta('description', 'My Great site');
273 // Generates: <meta name="description" content="My Great Site" />
274
275 echo meta('Content-type', 'text/html; charset=utf-8', 'equiv');
276 // Note the third parameter. Can be "equiv" or "name"
277 // Generates: <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
278
279 echo meta(array('name' => 'robots', 'content' => 'no-cache'));
280 // Generates: <meta name="robots" content="no-cache" />
281
282 $meta = array(         
283 array(
284 'name' => 'robots',
285 'content' => 'no-cache'
286 ),
287 array(
288 'name' => 'description',
289 'content' => 'My Great Site'
290 ),
291 array(
292 'name' => 'keywords',
293 'content' => 'love, passion, intrigue, deception'
294 ),         
295 array(
296 'name' => 'robots',
297 'content' => 'no-cache'
298 ),
299 array(
300 'name' => 'Content-type',
301 'content' => 'text/html; charset=utf-8', 'type' => 'equiv'
302 )
303 );
304
305 echo meta($meta);
306 // Generates:
307 // <meta name="robots" content="no-cache" />
308 // <meta name="description" content="My Great Site" />
309 // <meta name="keywords" content="love, passion, intrigue, deception" />
310 // <meta name="robots" content="no-cache" />
311 // <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
312
313doctype()
314=========
315
316Helps you generate document type declarations, or DTD's. XHTML 1.0
317Strict is used by default, but many doctypes are available.
318
319::
320
321 echo doctype(); // <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
322
323 echo doctype('html4-trans'); // <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
324
325The following is a list of doctype choices. These are configurable, and
326pulled from application/config/doctypes.php
327
Iban Eguia0baf2322012-01-27 20:21:43 +0100328+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
329| Doctype | Option | Result |
330+===============================+==============================+==================================================================================================================================================+
331| XHTML 1.1 | doctype('xhtml11') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
332+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
333| XHTML 1.0 Strict | doctype('xhtml1-strict') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
334+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
335| XHTML 1.0 Transitional | doctype('xhtml1-trans') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
336+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
337| XHTML 1.0 Frameset | doctype('xhtml1-frame') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> |
338+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
339| XHTML Basic 1.1 | doctype('xhtml-basic11') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd"> |
340+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
341| HTML 5 | doctype('html5') | <!DOCTYPE html> |
342+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
343| HTML 4 Strict | doctype('html4-strict') | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
344+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
345| HTML 4 Transitional | doctype('html4-trans') | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
346+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
347| HTML 4 Frameset | doctype('html4-frame') | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> |
348+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
349| MathML 1.01 | doctype('mathml1') | <!DOCTYPE math SYSTEM "http://www.w3.org/Math/DTD/mathml1/mathml.dtd"> |
350+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
351| MathML 2.0 | doctype('mathml2') | <!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd"> |
352+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
353| SVG 1.0 | doctype('svg10') | <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> |
354+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
355| SVG 1.1 Full | doctype('svg11') | <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> |
356+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
357| SVG 1.1 Basic | doctype('svg11-basic') | <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd"> |
358+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
359| SVG 1.1 Tiny | doctype('svg11-tiny') | <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd"> |
360+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
361| XHTML+MathML+SVG (XHTML host) | doctype('xhtml-math-svg-xh') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"> |
362+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
363| XHTML+MathML+SVG (SVG host) | doctype('xhtml-math-svg-sh') | <!DOCTYPE svg:svg PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"> |
364+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
365| XHTML+RDFa 1.0 | doctype('xhtml-rdfa-1') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> |
366+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
367| XHTML+RDFa 1.1 | doctype('xhtml-rdfa-2') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd"> |
368+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+