BladeOneHtml: Create HTML forms using compiled templates

Recommend this page to a friend!
  Info   View files Example   View files View files (24)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-04-20 (2 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 71 All time: 9,635 This week: 291Up
Version License PHP version Categories
bladeonehtml 1.0GNU Lesser Genera...5HTML, PHP 5, Cache, Templates
Description Author

This package can be used to create HTML forms using compiled templates.

It provides a trait that can be used in any class to process a view file that is a PHP script with some form template marks.

The trait loads the PHP script and processes the template by compiling it into another PHP script.

The compiled form template script will output the form HTML to display the form in the user browser.

On a second time the form is outputted again, the trait will load the previously compile form template, thus avoiding to process the template file again.

The trait can take also an array with values that will be loaded in the form inputs, so it may show the form loaded with previously submitted input values.

  Performance   Level  
Name: Jorge Castro <contact>
Classes: 18 packages by
Country: Chile Chile
Age: 44
All time rank: 16975 in Chile Chile
Week rank: 29 Up1 in Chile Chile Up
Innovation award
Innovation award
Nominee: 8x

Winner: 1x

Details

BladeOneHtml

It is a PHP library that allows to create forms (view) easily, cleanly and without killing the performance. It uses the library BladeOne to renders the view. This library only uses a single dependency, one file and nothing more.

This library works in two ways:

  • It compiles a script (our view that use our tags), in a native php code.
  • And the next read, if the script exists, then it uses it (instead of re-compiling). And since the script is native code, then it is exactly like to work in vanilla-php but it is way easy to write and to maintenance.

Packagist Total Downloads [Maintenance]() [composer]() [php]() [php]() [CocoaPods]()

Usage

  1. This library requires eftec/bladeone. You could install via Composer in the root folder of your project as

> composer require eftec/bladeonehtml

  1. And you should extend the class as follow (BladeOneHtml is a Trait)
include "vendor/autoload.php";

use eftec\bladeone\BladeOne;
use eftec\bladeonehtml\BladeOneHtml;

class myBlade extends  BladeOne {
    use BladeOneHtml;
}

$blade=new myBlade();

// for our example:
$myvalue=@$_REQUEST['myform'];
echo $blade->run("exampleview", ['myvalue'=>$myvalue]);

  1. Create a folders called ? "\views" and ? "\compiles"
  2. Inside views, creates the next file ? "\views\exampleview.blade.php"
<body>
    @form()
        @input(type="text" name="myform" value=$myvalue)
        @button(type="submit" value="Send")
    @endform()
</body>

$blade=new myBlade();

![](docs\img1.jpg)

Template basic

This library adds a new set of tags for the template. The tags uses named arguments, so it is easily configurable.

> @<tag>(argument1="value" argument2='value' argument3=value argument4=$variable argument5=function(), argument6="aaa $aaa")

This library uses the native html arguments but some arguments are special

| Argument | Description | example | | -------- | ------------------------------------------------------------ | ------------------------------------------------------------ | | text | It adds a content between the tags. The inner value is always un-quoted. | @tag(text="hello") -> < tag>hello< /tag> | | pre | It adds a content before the tag | @tag(pre="hello") -> hello< tag>< /tag> | | post | It adds a content after the tag | @tag(post="hello") -> < tag>< /tag>hello | | between | It adds a content between the tags (it works similar than text) | @tag(between="hello") -> < tag>hello< /tag> | | value | Usually it works as the normal "value" of html but it also could works differently (in @textarea works like text) | @tag(value="hello") -> < tag value="hello">< /tag> | | values | Some components needs a list of object/arrays. This argument is used to sets the list of values | @tag(values=$countries) | | alias | Some components needs or use a list of object/array. This argument is to reference any row inside the list. If values is set and alias is missing, then it creates a new alias called values+"Row". | @tag($values=$countries alias=$country)<br />@tag($values=$countries ) it asumes alias=$countriesRow | | optgroup | The tag @select could list grouped elements. This argument is used to set the grouping | @tag($values=$countries alias=$country @optgroup=$country->continent) |

Let's say the next example

@input(value="hello world" type="text" )

It is rendered as

<input value="hello world" type="text" />

If the tag uses a variable of function, then this view

@input(value=$hello type="text" )

Is converted into

<input value="<?php echo $this->e($hello);?>" type="text" /> 

The method $this->e is used to escape the method.

> Note: This library allows any tag, even custom tags (but only if they don't enter in conflict with the special tags, see table) > > @input(value="hello world" type="text" mycustomtag="hi" ) > > Is converted into > > <input value="hello world" type="text" mycustomtag="hi" />

Template usage

input

It shows a input html.

Basic example:

@input(id="id1" value="hello world$somevar" type="text" )

![](docs/input_label.jpg)

label

It shows a label html

@label(for="id1" text="hello world:") 

![](docs/input_label.jpg)

image

It shows an image

@image(src="https://via.placeholder.com/350x150")

![](docs/image.jpg)

select

It shows a select (dropdown list) html object

Example:

@select(id="aaa" value=$selection values=$countries alias=$country)
    @item(value='aaa' text='hello world')
    @item(value='aaa' text='hello world')
    @item(value='aaa' text='hello world')
    @items( id="chkx" value=$country->id text=$country->name)
@endselect

> Note: items requires to set arguments

![](docs/select.jpg)

item

It is an utilitarian tag used inside some tags. This behave depending of their parent tag. It adds a simple line/row to the parent object.

Example:

@select()
    @item(value='aaa' text='hello world')
@endselect

It renders

<select>
<option value="aaa">hello world</option>
</select>

items

It is an utilitarian tag used inside some tags. This behave depending of their parent tag. It adds a multiples lines/rows to the parent object using the tag values

> Note: This tag requires some arguments: > > the parent(or this tag) requires the tagvalues* > the parent requires the tagvalue* It indicates the current selection (if any) > the parent(or this tag) requires the tagalias* If alias is missing the it uses the name of values + "Row", i.e. values=product -> alias= productRow > the parent(or this tag) requires the tagid* > * The rendered "id" will be generated using this id+"_"+"id of the row". i.e. id="idproduct" => idproduct_0, idproduct_1 > * Why? It is because the id must be unique (html specs)

Example, if $countries is a list of objects then :

@select(id="aaa" value=$selection values=$countries alias=$country)
    @items( id="chkx" value=$country->id text=$country->name)
@endselect

If $countries is a list of arrays then:

@select(id="aaa" value=$selection values=$countries alias=$country)
    @items( id="chkx" value=$country['id'] text=$country['name'])
@endselect

Inside the tag items, you could use the next variables

| variable (where values is the variable used) | Specification | | -------------------------------------------------------- | ------------------------------------------------------------ | | $valuesOptGroup | It stores the current optgroup (if any). Example: $productOptGroup | | $valuesKey | It indicates the current key of the current row. Example: $productKey | | $alias (if not alias is set then it uses $valuesRow) | The current row of the variable. Example: $productRow |

optgroup

It starts an optional group (select)

Example:

@select(id="aaa" value=$selection values=$countries alias=$country)
    @optgroup(label="group1")
        @item(value='aaa' text='hello world')
        @item(value='aaa' text='hello world')
        @item(value='aaa' text='hello world')
    @endoptgroup
@endselect

> Note: this tag must be ended with the tag @endoptgroup

![](docs/optgroup.jpg)

checkbox

It adds a single checkbox

Example:

@checkbox(id="idsimple" value="1" checked="1" post="it is a selection")

![](docs/checkbox.jpg)

radio

It adds a single radio button

Example:

@radio(id="idsimple" value="1" checked="1" post="it is a selection")

![](docs/radio.jpg)

textarea

It draws a text area.

Example:

@textarea(id="aaa" value="3333 3333 aaa3333 ")

![](docs/textarea.jpg)

button

It draws a button

Example:

@button(value="click me" type="submit" class="test" onclick='alert("ok")')

![](docs/button.jpg)

link

It adds an hyperlink

Example:

@link(href="https://www.google.cl" text="context")

![](docs/link.jpg)

checkboxes

It shows a list of checkboxes

@checkboxes(id="checkbox1" value=$selection alias=$country)
    @item(id="aa1" value='aaa' text='hello world' post="<br>")
    @item(id="aa2" value='aaa' text='hello world2' post="<br>")
    @items(values=$countries value='id' text='name' post="<br>")
@endcheckboxes

![](docs/checkbox.jpg)

radios

It shows a list of radio buttons

@radios(id="radios1" name="aaa" value=$selection  alias=$country)
    @item(value='aaa' text='hello world' post="<br>")
    @item(value='aaa' text='hello world2' post="<br>")
    @items(values=$countries value='id' text='name' post="<br>")
@endradios

![](docs/radio.jpg)

file

It generates a file input value

@file(name="file" value="123.jpg" post="hello world")

> Note: it also renders a hidden file with name "name"+"_file" with the original value

![](docs/file.jpg)

ul

It generates an unsorted list

@ul(id="aaa" value=$selection values=$countries alias=$country)
    @item(value='aaa' text='hello world')
    @item(value='aaa' text='hello world')
    @item(value='aaa' text='hello world')
    @items(value=$country->id text=$country->name)
@endul

![](docs/ul.jpg)

ol

It generates a sorted list

@ol(id="aaa" value=$selection values=$countries alias=$country)
    @item(value='aaa' text='hello world')
    @item(value='aaa' text='hello world')
    @item(value='aaa' text='hello world')
    @items(value=$country->id text=$country->name)
@endol

![](docs/ol.jpg)

table

It renders a table

@table(class="table" values=$countries alias=$country border="1")
    @tablehead  
        @cell(text="id")
        @cell(text="cod")
        @cell(text="name")
    @endtablehead
    @tablebody(id='hello world'  )
        @tablerows(style="background-color:azure")
            @cell(text=$country->id style="background-color:orange")
            @cell(text=$country->cod )
            @cell(text=$country->name)
        @endtablerows
    @endtablebody
    @tablefooter
        @cell(text="id" colspan="3")
    @endtablefooter
@endtable

![](docs/table.jpg)

tablehead

It renders the header of the table (optional). Each cell added inside it, is rendered as "th" html tag

tablebody

It renders the body of the table (optional). Each cells added inside it, is rendered as "td" html tag

tablefooter

It renders the footer of the table (optional). Each cell added inside it, is rendered as "th" html tag

tablerows

It generates a row inside the body

cells

It renders a cell inside the tablehead,tablebody (tablerows) or tablefooter

Version history

1.0 2020-04-20 First version

  Files folder image Files  
File Role Description
Files folder imagedocs (14 files)
Files folder imageexamples (3 files, 1 directory)
Files folder imagelib (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files  /  docs  
File Role Description
  Accessible without login Image file button.jpg Icon Icon image
  Accessible without login Image file checkbox.jpg Icon Icon image
  Accessible without login Image file file.jpg Icon Icon image
  Accessible without login Image file image.jpg Icon Icon image
  Accessible without login Image file img1.jpg Icon Icon image
  Accessible without login Image file input_label.jpg Icon Icon image
  Accessible without login Image file link.jpg Icon Icon image
  Accessible without login Image file ol.jpg Icon Icon image
  Accessible without login Image file optgroup.jpg Icon Icon image
  Accessible without login Image file radio.jpg Icon Icon image
  Accessible without login Image file select.jpg Icon Icon image
  Accessible without login Image file table.jpg Icon Icon image
  Accessible without login Image file textarea.jpg Icon Icon image
  Accessible without login Image file ul.jpg Icon Icon image

  Files folder image Files  /  examples  
File Role Description
Files folder imageviews (1 file, 1 directory)
  Accessible without login Plain text file example1.php Example Example script
  Accessible without login Plain text file testextension3.php Example Example script
  Accessible without login Plain text file testextension3_bs.php Example Example script

  Files folder image Files  /  examples  /  views  
File Role Description
Files folder imageTestExtension (2 files)
  Accessible without login Plain text file exampleview.blade.php Aux. Auxiliary script

  Files folder image Files  /  examples  /  views  /  TestExtension  
File Role Description
  Accessible without login Plain text file helloextensions3.blade.php Aux. Auxiliary script
  Accessible without login Plain text file helloextensions3_bs.blade.php Aux. Auxiliary script

  Files folder image Files  /  lib  
File Role Description
  Plain text file BladeOneHtml.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:71
This week:0
All time:9,635
This week:291Up

For more information send a message to info at phpclasses dot org.