PHP code example of jnjxp / html

1. Go to this page and download the library: Download jnjxp/html 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/ */

    

jnjxp / html example snippets


use Jnjxp\Html\Factory as HtmlFactory;

$helper = (new HtmlFactory())->newInstance();

// example calling the icon helper
$helper->icon('foo');
$helper->icon->__invoke('foo');
$helper('icon','foo');


$helper->breadcrumb(['id' => 'test']);  // (array) optional attributes

// add a single item to be escaped
$helper->breadcrumb()
    ->item('Home', '/', ['class' => 'foo']); // (title, uri, attributes)

// add several items to be escaped
$helper->breadcrumb()->items(
    [ // key as uri value as title or array of attributes with title as first key
        '/' => 'Home',
        '/foo' => [ 'Foo', 'class' => 'foo']
        'Bar' // numeric index, URI defaults to "#"
    ]
);

// add a single raw item not to be escaped
$helper->breadcrumb()->rawItem('<span>Home</span>', '/', ['class' => 'foo']);

// add several raw items not to be escaped
$helper->breadcrumb()->items(
    [
        '/' => '<span>Home</span>',
        '/foo' => ['Foo', 'class' => 'foo']
        'Bar'
    ]
);


// set path to public root
$helper->cacheBust->setPublic('/var/www');

// returns /build/assets/js/app-a9341845.js
$helper->cacheBust('assets/js/app.js', 'build/rev-manifest.json');

// can set a default manifest as well
$helper->cacheBust->setDefaultManifest('build/rev-manifest.json');
$helper->cacheBust('assets/js/app.js');

echo $helper->icon('edit');
echo $helper->icon('edit', 'Edit Entry');
echo $helper->icon('edit', true);

$helper->links->icons();
echo $helper->links;

// can pass array to override defaults:
$icons = [
    'apple-touch-icon' => [
        'pattern' => '/assets/ico/apple-touch-icon-%sx%1$s.png',
        'sizes' => [144, 114, 72, 57]
    ],
    'icon' => [
        'pattern' => '/assets/ico/favicon-%sx%1$s.png',
        'sizes' => [192, 96, 32, 16],
        'attr' => ['type' => 'image/png']
    ]
];

$helper->links->icons($icons);

$helper->metas()
    ->addProperty('foo', 'bar')
    ->addOpenGraphProperty('foo', 'bar')
    ->charset() // pass arg to override default
    ->compat() // pass arg to override default
    ->description('description here')
    ->loc() // pass arg to override default
    ->robots('noindex, follow') // no arg? defaults to 'index, follow'
    ->url('http://example.com')
    ->viewport() // pass arg to override default
    ->image('/image.png');

echo $helper->metas();


echo $helper->modal(['attr' => ['id' => 'test']])
    ->setTitle('Test Modal')
    ->setBody('Body Here')
    ->setFooter('Modal Footer')
    ->setButton('Launch', ['class' => 'btn-success']);

// Or...

echo $helper->modal(
    [
        'attr'   => ['id' => 'test'],
        'title'  => 'Test Modal',
        'body'   => 'Body Here',
        'footer' => 'Modal Footer',
        'button' => ['Launch', ['class' => 'btn-sucess']]
    ]
);


$helper->scripts->bust()
    ->setPublic('/var/www/')
    ->setDefaultManifest('build/rev-manifest.json');

$helper->scripts->bust()->add('assets/js/app.js');

$helper->scripts->addInline('alert("foo")');
$helper->scripts->addEventListener('function(){alert("foo")}');

$helper->scripts->addEventListener(
    'alert(event.type)', // snippet
    'click', // event type
    'document.document.getElementById("test")', // target
    true // wrap snippet in function?
);

$helper->scripts->inlineCaptureStart();
echo 'alert("foo")';
$helper->scripts->captureEnd();


$helper->scripts->eventCaptureStart();
// can take same args as addEventListener
echo 'alert("foo")';
$helper->scripts->captureEnd();

echo $helper->scripts;


$helper->styles->bust()
    ->setPublic('/var/www/')
    ->setDefaultManifest('build/rev-manifest.json');

$helper->styles->bust()->add('assets/css/style.css');

$helper->styles->addInline('.test{color:red;}');

$helper->styles->inlineCaptureStart();
echo ".test{color:red;}";
$helper->styles->captureEnd();

echo $helper->styles;


$helper->title
    ->set('Page Title')
    ->setSite('Site Title');

echo $helper->title;