PHP code example of levizwannah / php-markup

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

    

levizwannah / php-markup example snippets




use LeviZwannah\PhpMarkup\Facades\Markup as pm;

pm::div(
    class: 'mb-2',
    id: 'div-id'
    children: [
        pm::p('This is a paragraph a child of div')
    ],
    print: true
);




use LeviZwannah\PhpMarkup\Facades\Markup as pm;

pm::div(
    pm::p('This is a paragraph a child of div'), // child first,
    pm::div(
        'Inner Text for div',
        pm::span('A span elem')
    ),
    class: 'mb-2', // then attributes
    id: 'div-id'
    print: true
);




use LeviZwannah\PhpMarkup\Facades\Markup as pm;

pm::div(
    class: 'mb-2', // then attributes
    id: 'div-id',
    children: [
        pm::p('This is a paragraph a child of div'), // child first,
        pm::div(
            'Inner Text for div',
            pm::span('A span elem')
        ),
    ]
    print: true
);


pm::html(
    ...$args,
    print: true
);
 
pm::div(
    id: 'div-1',
    class: 'div',
    children1: [
        pm::p(
            id: 'p-1'
            class: 'p-class',
            text: 'This is the first paragraph'
        ),
        "This is some text", // position is observed
        pm::p(
            id: 'p-2',
            class: 'p-class',
            text: 'This is the second paragraph'
        )
    ],
    exec1: function(){
        return '... Some function executes here then...'
    },
    children2: [
        pm::p(
            id: 'p-3',
            class: 'p-class',
            text: 'This is the third paragraph'
        ),
        pm::span(
            id: 'span-1',
            text: 'This is a span'
        )
    ],

    print: true // print out this div
);

component(string $name, \Closure $render, array $specialArgs = []): self

pm::blogList(
    class: 'some-class'
    blogs: $array,
    data_name: 'some data attribute'
)

# blog.php
use LeviZwannah\PhpMarkup\Facades\Markup as pm;

pm::component(
    name: "blog",
    render: function($specialArgs, $args, $after = []){
        $output = "";

        $content = $specialArgs['content'];

        foreach($content as $blog){
            $output .= pm::div(
                "This is a div for $blog",
                ...$args // pass the remaining args to the child div
                after: $after
            );
        }

        return $output;
    },
    specialArgs: ['content']
);

# index.php
h::div(
    class : "container card m-3 w-full",
  
    # ...

    children: [
        h::blog(
            h::h1("Hello There"),
            class: 'p-4 m-2',
            content: $blogArray
        )
    ] 
),

h::you(
    class: 'you-class',
    id: 'you-1',
    text: 'Hello you'
);

/**
 * @param string $name - The name of the element
 * @param array $args - The list of arguments passed to the function
 * during creation. For example pm::div(...args)
 * @param bool $return - should the created string be printed or returned?
 * @param array<string> $after - callbacks to execute on the final content 
 * before it is returned or printed.
 * 
 */
handle(string $name, array $args, bool $return = true, $after = [])

# custom-tags.php
use LeviZwannah\PhpMarkup\Facades\Markup as pm;

pm::component(
    name: "p",
    render: function($specialArgs, $args, $after = []){
        # add more classes to p
        $classes = $args['class'] ?? "";
        $classes = "custom-p-class $classes custom-p-class-2";
        $args['class'] = $classes;

        # you could even put the p in a div by default.

        return pm::handle('p', $args, $after);
    },
    specialArgs: []
);