View Helper - HtmlList?

Introduction?

htmlList($items, $ordered, $attribs, $escape): generates unordered and ordered lists based on the $items passed to it. If $items is a multidimensional array, a nested list will be built. If the $escape flag is TRUE (default), individual items will be escaped using the view objects registered escaping mechanisms; pass a FALSE value if you want to allow markup in your lists.

Basic Usage?

Unordered list?

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
$items = array(
    'Level one, number one',
    array(
        'Level two, number one',
        'Level two, number two',
        array(
            'Level three, number one'
        ),
        'Level two, number three',
    ),
    'Level one, number two',
 );

echo $this->htmlList($items);

Output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
  • Level one, number one
    • Level two, number one
    • Level two, number two
      • Level three, number one
      • Level two, number three
      • Level one, number two

        Ordered list?

        1
        echo $this->htmlList($items, true);
        

        Output:

         1
         2
         3
         4
         5
         6
         7
         8
         9
        10
        11
        12
        13
        14
        1. Level one, number one
          1. Level two, number one
          2. Level two, number two
            1. Level three, number one
            2. Level two, number three
            3. Level one, number two

              HTML attributes?

              1
              2
              3
              4
              5
              $attribs = array(
                  'class' => 'foo',
              );
              
              echo $this->htmlList($items, false, $attribs);
              

              Output:

               1
               2
               3
               4
               5
               6
               7
               8
               9
              10
              11
              12
              13
              14
              <> class="foo">
                  
            4. Level one, number one <> class="foo">
            5. Level two, number one
            6. Level two, number two <> class="foo">
            7. Level three, number one
            8. Level two, number three
            9. Level one, number two

              Escape Output?

               1
               2
               3
               4
               5
               6
               7
               8
               9
              10
              $items = array(
                  'Level one, number one',
                  'Level one, number two',
               );
              
              // Escape output (default)
              echo $this->htmlList($items);
              
              // Don't escape output
              echo $this->htmlList($items, false, false, false);
              

              Output:

               1
               2
               3
               4
               5
               6
               7
               8
               9
              10
              11
              
              <> class="foo">
                  
            10. Level one, number <strong>one</strong>
            11. Level one, number <em>two</em> <> class="foo">
            12. Level one, number one
            13. Level one, number two

              Table Of Contents

              Previous topic

              View Helper - HeadTitle

              Next topic

              View Helper - HTML Object

              This Page

              Note: You need to stay logged into your GitHub account to contribute to the documentation.

              Edit this document

              Edit this document

              The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

              1. Login with your GitHub account.
              2. Go to View Helper - HtmlList on GitHub.
              3. Edit file contents using GitHub's text editor in your web browser
              4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
              5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
              6. Your changes are now queued for review under project's Pull requests tab on GitHub.