PHP code example of hexmakina / marker

1. Go to this page and download the library: Download hexmakina/marker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hexmakina / marker example snippets


use HexMakina\Marker\Element;
use HexMakina\Marker\Marker;
use HexMakina\Marker\Form;

$element = new Element('section', 'Hello World!', [
    'id'          => 'publication',
    'class'       => 'container',
    'data-toggle' => 'modal',
    'data-target' => '#myModal',
]);

echo $element;
// <section id="publication" class="container" data-toggle="modal" data-target="#myModal">Hello World!</section>

echo Element::span('inner text', ['class' => 'd-block']);
// <span class="d-block">inner text</span>

echo Element::p('lorem ipsum');
// <p>lorem ipsum</p>

echo new Element('p', '<script>alert(1)</script>');
// <p>&lt;script&gt;alert(1)&lt;/script&gt;</p>

$abbr = new Element('abbr', 'RTFM', ['title' => 'read the manual']);

// Trusted parent: the child markup survives intact.
echo new Element('p', 'See ' . $abbr, [], false);
// <p>See <abbr title="read the manual">RTFM</abbr></p>

> echo new Element('p', 'See ' . $abbr);
> // <p>See &lt;abbr title=&quot;read the manual&quot;&gt;RTFM&lt;/abbr&gt;</p>
> 

echo new Element('img', null, ['src' => 'a.jpg', 'alt' => 'x']);
// <img src="a.jpg" alt="x">

echo new Element('br');
// <br>

echo new Element('input', null, [
    'type' => 'checkbox',
    'checked',            // integer key -> boolean attribute
    'disabled',           // integer key -> boolean attribute
    'class' => 'c',       // string key  -> name="value"
]);
// <input type="checkbox" checked disabled class="c">

new Element('123');            // throws: Invalid HTML tag name "123"
$el = new Element('div');
$el->{'bad attr'} = 'x';       // throws: Invalid HTML attribute name "bad attr"

$el = new Element('div', 'body', ['id' => 'main']);
$el->class = 'container';     // set
echo $el->id;                 // "main"
echo isset($el->id) ? 'y':'n';// "y"
unset($el->class);            // remove

// <img> — src and alt come first; alt is copied to title if not given.
echo Marker::img('a.jpg', 'alt text', ['width' => 100]);
// <img width="100" src="a.jpg" alt="alt text" title="alt text">

// <a> — href first, then label.
echo Marker::a('/dest', 'Click', ['class' => 'nav']);
// <a class="nav" href="/dest">Click</a>

echo Form::input('email', '[email protected]', ['label' => 'Email']);
// <label for="email">Email</label><input name="email" value="[email protected]" type="text" id="email">

echo Form::hidden('token', 'abc');   // <input type="hidden" ...>
echo Form::date('due', '2026-01-01');
echo Form::datetime('when', '...');  // type becomes "datetime-local"
echo Form::password('pw', 'secret'); // value is always blanked for passwords

echo Form::input('agree', '1', ['type' => 'checkbox', 'disabled']);
// <input type="checkbox" disabled name="agree" value="1" id="agree">

echo Form::input('email', '[email protected]', ['label' => 'Email']);
// <label for="email">Email</label><input ... id="email">

echo Form::input('agree', '1', ['type' => 'checkbox', 'label' => 'I agree', 'label-wrap' => true]);
// <label>I agree<input type="checkbox" name="agree" value="1" id="agree"></label>

echo Form::textarea('bio', 'Hello', ['label' => 'Bio']);
// <label for="bio">Bio</label><textarea name="bio" id="bio">Hello</textarea>

echo Form::select('color', [1 => 'Red', 2 => 'Blue'], 2, ['label' => 'Color']);
// <label for="color">Color</label><select name="color" id="color"><option value="1">Red</option><option value="2" selected="selected">Blue</option></select>

echo Form::submit('save', 'Save');
// <button type="submit" id="save">Save</button>

echo Form::submit('save', 'Save', ['tag' => 'input']);
// <input type="submit" id="save" value="Save">   (rendered as a void element)

echo Form::button('Cancel', ['class' => 'btn']);
// <button class="btn">Cancel</button>

echo Form::legend('Account');
// <legend>Account</legend>