blob: df53ebd2f0a9410683fc8586e6492bf7a01b63aa [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
Andrey Andreev53b8ef52012-11-08 21:38:53 +020022.. php:function:: br($count = 1)
23
24 :param int $count: Number of times to repeat the tag
25 :returns: string
26
Derek Jones8ede1a22011-10-05 13:34:52 -050027Generates line break tags (<br />) based on the number you submit.
28Example::
29
30 echo br(3);
31
32The above would produce: <br /><br /><br />
33
34heading()
35=========
36
Andrey Andreev53b8ef52012-11-08 21:38:53 +020037.. php:function:: heading($data = '', $h = '1', $attributes = '')
38
39 :param string $data: Content
40 :param string $h: Heading level
41 :param array $attributes: HTML attributes
42 :returns: string
43
44Lets you create HTML heading tags. The first parameter will contain the
Derek Jones8ede1a22011-10-05 13:34:52 -050045data, the second the size of the heading. Example::
46
47 echo heading('Welcome!', 3);
48
49The above would produce: <h3>Welcome!</h3>
50
51Additionally, in order to add attributes to the heading tag such as HTML
Andrey Andreev53b8ef52012-11-08 21:38:53 +020052classes, ids or inline styles, a third parameter is available::
Derek Jones8ede1a22011-10-05 13:34:52 -050053
54 echo heading('Welcome!', 3, 'class="pink"')
55
56The above code produces: <h3 class="pink">Welcome!<<h3>
57
58img()
59=====
60
Andrey Andreev53b8ef52012-11-08 21:38:53 +020061.. php:function:: img($src = '', $index_page = FALSE, $attributes = '')
Derek Jones8ede1a22011-10-05 13:34:52 -050062
Andrey Andreev53b8ef52012-11-08 21:38:53 +020063 :param string $src: Image source data
64 :param bool $index_page: Whether to treat $src as a routed URI string
65 :param array $attributes: HTML attributes
66 :returns: string
67
68Lets you create HTML <img /> tags. The first parameter contains the
69image source. Example::
Derek Jones8ede1a22011-10-05 13:34:52 -050070
71 echo img('images/picture.jpg'); // gives <img src="http://site.com/images/picture.jpg" />
72
73There is an optional second parameter that is a TRUE/FALSE value that
Andrey Andreev53b8ef52012-11-08 21:38:53 +020074specifics if the *src* should have the page specified by
75``$config['index_page']`` added to the address it creates.
76Presumably, this would be if you were using a media controller::
Derek Jones8ede1a22011-10-05 13:34:52 -050077
78 echo img('images/picture.jpg', TRUE); // gives <img src="http://site.com/index.php/images/picture.jpg" alt="" />
79
80
Andrey Andreev53b8ef52012-11-08 21:38:53 +020081Additionally, an associative array can be passed to the ``img()`` function
82for complete control over all attributes and values. If an *alt* attribute
Derek Jones8ede1a22011-10-05 13:34:52 -050083is not provided, CodeIgniter will generate an empty string.
84
Andrey Andreev53b8ef52012-11-08 21:38:53 +020085Example::
Derek Jones8ede1a22011-10-05 13:34:52 -050086
87 $image_properties = array(           
88 'src' => 'images/picture.jpg',           
89 'alt' => 'Me, demonstrating how to eat 4 slices of pizza at one time',  
90 'class' => 'post_images',           
91 'width' => '200',           
92 'height'=> '200',           
93 'title' => 'That was quite a night',           
94 'rel' => 'lightbox'
95 );
96
Andrey Andreev53b8ef52012-11-08 21:38:53 +020097 img($image_properties);
98 // <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" />
Derek Jones8ede1a22011-10-05 13:34:52 -050099
100
101link_tag()
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200102==========
103
104.. php:function:: ling_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE)
105
106 :param string $href: What are we linking to
107 :param string $rel: Relation type
108 :param string $type: Type of the related document
109 :param string $title: Link title
110 :param string $media: Media type
111 :param bool $index_page: Whether to treat $src as a routed URI string
112 :returns: string
Derek Jones8ede1a22011-10-05 13:34:52 -0500113
114Lets you create HTML <link /> tags. This is useful for stylesheet links,
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200115as well as other links. The parameters are *href*, with optional *rel*,
116*type*, *title*, *media* and *index_page*.
Derek Jones8ede1a22011-10-05 13:34:52 -0500117
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200118*index_page* is a boolean value that specifies if the *href* should have
119the page specified by ``$config['index_page']`` added to the address it creates.
Derek Jones8ede1a22011-10-05 13:34:52 -0500120
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200121Example::
122
123 echo link_tag('css/mystyles.css');
124 // gives <link href="http://site.com/css/mystyles.css" rel="stylesheet" type="text/css" />
Derek Jones8ede1a22011-10-05 13:34:52 -0500125
126
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200127Further examples::
Derek Jones8ede1a22011-10-05 13:34:52 -0500128
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200129 echo link_tag('favicon.ico', 'shortcut icon', 'image/ico');
130 // <link href="http://site.com/favicon.ico" rel="shortcut icon" type="image/ico" />
Derek Jones8ede1a22011-10-05 13:34:52 -0500131
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200132 echo link_tag('feed', 'alternate', 'application/rss+xml', 'My RSS Feed');
133 // <link href="http://site.com/feed" rel="alternate" type="application/rss+xml" title="My RSS Feed" />
Derek Jones8ede1a22011-10-05 13:34:52 -0500134
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200135Additionally, an associative array can be passed to the ``link()`` function
136for complete control over all attributes and values::
Derek Jones8ede1a22011-10-05 13:34:52 -0500137
138 $link = array(           
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200139 'href' => 'css/printer.css',
140 'rel' => 'stylesheet',
141 'type' => 'text/css',
142 'media' => 'print'
Derek Jones8ede1a22011-10-05 13:34:52 -0500143 );
144
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200145 echo link_tag($link);
146 // <link href="http://site.com/css/printer.css" rel="stylesheet" type="text/css" media="print" />
Derek Jones8ede1a22011-10-05 13:34:52 -0500147
148nbs()
149=====
150
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200151.. php:function:: nbs($num = 1)
Derek Jones8ede1a22011-10-05 13:34:52 -0500152
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200153 :param int $num: Number of space entities to produce
154 :returns: string
155
156Generates non-breaking spaces (&nbsp;) based on the number you submit.
157Example::
Derek Jones8ede1a22011-10-05 13:34:52 -0500158
159 echo nbs(3);
160
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200161The above would produce::
Derek Jones8ede1a22011-10-05 13:34:52 -0500162
163 &nbsp;&nbsp;&nbsp;
164
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200165ul() and ol()
Derek Jones8ede1a22011-10-05 13:34:52 -0500166=============
167
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200168.. php:function:: ul($list, $attributes = '')
169
170 :param array $list: List entries
171 :param array $attributes: HTML attributes
172 :returns: string
173
Derek Jones8ede1a22011-10-05 13:34:52 -0500174Permits you to generate ordered or unordered HTML lists from simple or
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200175multi-dimensional arrays. Example::
Derek Jones8ede1a22011-10-05 13:34:52 -0500176
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200177 $list = array(
178 'red',
179 'blue',
180 'green',
181 'yellow'
Derek Jones8ede1a22011-10-05 13:34:52 -0500182 );
183
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200184 $attributes = array(
185 'class' => 'boldlist',
186 'id' => 'mylist'
Derek Jones8ede1a22011-10-05 13:34:52 -0500187 );
188
189 echo ul($list, $attributes);
190
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200191The above code will produce this::
Derek Jones8ede1a22011-10-05 13:34:52 -0500192
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200193 <ul class="boldlist" id="mylist">
194 <li>red</li>
195 <li>blue</li>
196 <li>green</li>
Derek Jones8ede1a22011-10-05 13:34:52 -0500197 <li>yellow</li>
198 </ul>
199
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200200Here is a more complex example, using a multi-dimensional array::
Derek Jones8ede1a22011-10-05 13:34:52 -0500201
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200202 $attributes = array(
203 'class' => 'boldlist',
204 'id' => 'mylist'
Derek Jones8ede1a22011-10-05 13:34:52 -0500205 );
206
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200207 $list = array(
208 'colors' => array(
209 'red',
210 'blue',
211 'green'
Derek Jones8ede1a22011-10-05 13:34:52 -0500212 ),
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200213 'shapes' => array(
214 'round',
215 'square',
216 'circles' => array(
Derek Jones8ede1a22011-10-05 13:34:52 -0500217 'ellipse',
218 'oval',
219 'sphere'
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200220 )
221 ),
222 'moods' => array(
223 'happy',
224 'upset' => array(
Derek Jones8ede1a22011-10-05 13:34:52 -0500225 'defeated' => array(
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200226 'dejected',
Derek Jones8ede1a22011-10-05 13:34:52 -0500227 'disheartened',
228 'depressed'
229 ),
230 'annoyed',
231 'cross',
232 'angry'
233 )
234 )
235 );
236
237 echo ul($list, $attributes);
238
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200239The above code will produce this::
Derek Jones8ede1a22011-10-05 13:34:52 -0500240
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200241 <ul class="boldlist" id="mylist">
242 <li>colors
243 <ul>
244 <li>red</li>
245 <li>blue</li>
246 <li>green</li>
247 </ul>
248 </li>
249 <li>shapes
250 <ul>
251 <li>round</li>
252 <li>suare</li>
253 <li>circles
254 <ul>
255 <li>elipse</li>
256 <li>oval</li>
257 <li>sphere</li>
258 </ul>
259 </li>
260 </ul>
261 </li>
262 <li>moods
263 <ul>
264 <li>happy</li>
265 <li>upset
266 <ul>
267 <li>defeated
268 <ul>
Derek Jones8ede1a22011-10-05 13:34:52 -0500269 <li>dejected</li>
270 <li>disheartened</li>
271 <li>depressed</li>
272 </ul>
273 </li>
274 <li>annoyed</li>
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200275 <li>cross</li>
276 <li>angry</li>
277 </ul>
278 </li>
279 </ul>
Derek Jones8ede1a22011-10-05 13:34:52 -0500280 </li>
281 </ul>
282
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200283.. php:function:: ol($list, $attributes = '')
284
285 :param array $list: List entries
286 :param array $attributes: HTML attributes
287 :returns: string
288
289Identical to :php:func:`ul()`, only it produces the <ol> tag for
290ordered lists instead of <ul>.
291
Derek Jones8ede1a22011-10-05 13:34:52 -0500292meta()
293======
294
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200295.. php:function:: meta($name = '', $content = '', $type = 'name', $newline = "\n")
Derek Jones8ede1a22011-10-05 13:34:52 -0500296
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200297 :param string $name: Meta name
298 :param string $content: Meta content
299 :param string $type: Meta type
300 :param string $newline: Newline character
301 :returns: string
302
303Helps you generate meta tags. You can pass strings to the function, or
304simple arrays, or multidimensional ones.
305
306Examples::
Derek Jones8ede1a22011-10-05 13:34:52 -0500307
308 echo meta('description', 'My Great site');
309 // Generates: <meta name="description" content="My Great Site" />
310
311 echo meta('Content-type', 'text/html; charset=utf-8', 'equiv');
312 // Note the third parameter. Can be "equiv" or "name"
313 // Generates: <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
314
315 echo meta(array('name' => 'robots', 'content' => 'no-cache'));
316 // Generates: <meta name="robots" content="no-cache" />
317
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200318 $meta = array(
Derek Jones8ede1a22011-10-05 13:34:52 -0500319 array(
320 'name' => 'robots',
321 'content' => 'no-cache'
322 ),
323 array(
324 'name' => 'description',
325 'content' => 'My Great Site'
326 ),
327 array(
328 'name' => 'keywords',
329 'content' => 'love, passion, intrigue, deception'
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200330 ),
Derek Jones8ede1a22011-10-05 13:34:52 -0500331 array(
332 'name' => 'robots',
333 'content' => 'no-cache'
334 ),
335 array(
336 'name' => 'Content-type',
337 'content' => 'text/html; charset=utf-8', 'type' => 'equiv'
338 )
339 );
340
341 echo meta($meta);
342 // Generates:
343 // <meta name="robots" content="no-cache" />
344 // <meta name="description" content="My Great Site" />
345 // <meta name="keywords" content="love, passion, intrigue, deception" />
346 // <meta name="robots" content="no-cache" />
347 // <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
348
349doctype()
350=========
351
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200352.. php:function:: doctype($type = 'xhtml1-strict')
353
354 :param string $type: Doctype name
355
Derek Jones8ede1a22011-10-05 13:34:52 -0500356Helps you generate document type declarations, or DTD's. XHTML 1.0
357Strict is used by default, but many doctypes are available.
358
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200359Example::
Derek Jones8ede1a22011-10-05 13:34:52 -0500360
361 echo doctype(); // <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
362
363 echo doctype('html4-trans'); // <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
364
365The following is a list of doctype choices. These are configurable, and
366pulled from application/config/doctypes.php
367
Iban Eguia0baf2322012-01-27 20:21:43 +0100368+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
369| Doctype | Option | Result |
370+===============================+==============================+==================================================================================================================================================+
371| XHTML 1.1 | doctype('xhtml11') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
372+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
373| 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"> |
374+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
375| 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"> |
376+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
377| 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"> |
378+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
379| 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"> |
380+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
381| HTML 5 | doctype('html5') | <!DOCTYPE html> |
382+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
383| HTML 4 Strict | doctype('html4-strict') | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
384+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
385| HTML 4 Transitional | doctype('html4-trans') | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
386+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
387| HTML 4 Frameset | doctype('html4-frame') | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> |
388+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
389| MathML 1.01 | doctype('mathml1') | <!DOCTYPE math SYSTEM "http://www.w3.org/Math/DTD/mathml1/mathml.dtd"> |
390+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
391| MathML 2.0 | doctype('mathml2') | <!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd"> |
392+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
393| 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"> |
394+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
395| 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"> |
396+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
397| 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"> |
398+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
399| 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"> |
400+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
401| 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"> |
402+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
403| 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"> |
404+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
405| 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"> |
406+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
407| 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"> |
408+-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+