<?php
$data = array('List 1','List 2', 'List 3');
$output = theme('item_list', $data);
?>
The Above use of theme function will output the <UL> and <LI> without any class or id.For Example:
<ul >
<li > List 1 </li>
<li > List 2 </li>
<li > List 3 </li>
</ul>
If we need to have the output as below.
For Example:
<h3> Title </h3>
<ul class="my-list">
<li clase="list" id="list-1"> List 1 </li>
<li clase="list" id="list-2"> List 2 </li>
<li clase="list" id="list-3"> List 3 </li>
</ul>
Then our code will look like.
<?php
$items = array(
array('data' => 'List 1', 'Class' => 'list', 'id' => 'list-1'),
array('data' => 'List 2', 'Class' => 'list', 'id' => 'list-2'),
array('data' => 'List 3', 'Class' => 'list', 'id' => 'list-3')
);
$title = 'Title';
$output = theme('item_list', $items, $title, 'ul', array('class' => 'my-list'));
?>
In $items array for each item we defined an array with key data, class and id, this will be transformed to HTML.
Title parameter will be printed prefix to the UL tag, with header tag.
And 'ul' parameter decides the type ordered / unordered tag to be printed. defualt is UL
Last a class attribute to UL tag, you may add id or any HTML attribute to UL / OL tag, defining inside the array as key => value.
Refer this in Drupal API
Nice Tutorial. Thanks For sharing :)
ReplyDeletePlease do mark your code for Drupal version.
ReplyDeleteDrupal is an incredible powerful open source CMS platform developed in PHP.
ReplyDeleteAlmost each net developer includes a favorite info that he/she feels snug operating with as all the tricks & gimmicks.
ReplyDeletegraphics design
open source software
graphic design portfolio
responsive themes
drupal themes
graphic design portfolio examples
design portfolio
open source softwares
open source database
best graphic design
Your blog is great. It’s very interesting
ReplyDelete