Create a Block

Learn the basics of creating your own blocks.


[PHP-] // PROTYPON CONTENT BLOCK / content-A / content $defaults = array( 'title' => 'Your Title', 'content' => $lorem, 'image_position' => 'left', 'show_title' => 'on', ); initData( $defaults );
first lines of a block php file
 

BLOCK HEADER

The first line of every block must start the php session and the second line should contain the block information in a format like above.
  • The line starts with // that declares it as a comment line and a space follows.
  • Then you should type your block's name
  • You separate the next value with space / space.
  • The second value is the block's filename (without the extension). So if your blocks filename is my-block.php this value should be my-block.
  • A separator follows and the last value is the block's group.

BLOCK DATA

Your blocks can contain dynamic data that can be altered easily during page design or content editing. Below the block's header, you should declare your dynamic data fields and their default values. You should define the $defaults array and enter your fields as it's properties.

In our example we have four fields. This is a block to contain some content for a page so it has a title and a content field. The content field is assigned the variable $lorem as default value. This is a string that contains some lorem ipsum text. This value acts as a placeholder and will only be displayed in editing mode, so the editor knows how the block looks and where to enter content. The same happens with the value 'Your Title'. The other two fields are options that will define the appearance of our block.

After the default array definition, we should execute the function initData() with the array as a parameter to initialize our fields. We can now use them in our block as follows:  $typos['title'], $typos['content'] etc.