Skip to content

Creating a HTML Menu

Thomas Weinert edited this page Jul 12, 2018 · 4 revisions

Creating a HTML Menu

FluentDOM provides some shortcut functions to create nodes. The following examples shows how to use them to create HTML by creating a menu.

Step 1: Create the base node

$document = new FluentDOM\DOM\Document();

// add the base menu node
$menu = $document->appendElement('ul', ['class' => 'navigation']);

// step 2

// output the created ul element as html
echo $document->documentElement->saveHtml();

Output:

<ul class="navigation"></ul>

Step 2: Add menu items

// add the first menu item
$menu
  ->appendElement('li')
  ->appendElement('a', 'Sample', ['href' => '/sample.php']);

// add the second menu item
$menu
  ->appendElement('li')
  ->appendElement('a', 'FluentDOM', ['href' => 'http://fluentdom.org']);

Output

<ul class="navigation">
<li><a href="/sample.php">Sample</a></li>
<li><a href="http://fluentdom.org">FluentDOM</a></li>
</ul>
Clone this wiki locally