Block

Skip to end of metadata
Go to start of metadata

A block element is a iterating component which is really powerful.
Basically a block is only a loop, but you can use other editables in this loop, so it's possible to reapeat a set of editables to create a structured page.
How the amount of the loops can be defined by the editor with the block controls. This controls also allow it to change the sequence of the contents.

Configuration

Name
Type
Description
limit
integer
Max. amount if iterations
default
integer
If block is empty, this specifies the iterations at startup
manual bool forces the manual mode, which enables a complete free implementation for blocks, for example using read <table> elements
... example see blelow (since 1.4.5)

Methods

Name
Description
getCount()
Get the total amount of iterations
getCurrent()
Get the current index while looping

The Block Controls

Control Operation
Add a new block at the current position
Remove the current block
Move block up
Move block down

Basic usage

<?php while($this->block("contentblock")->loop()) { ?>
    <h2><?php echo $this->input("subline"); ?></h2>
    <?php echo $this->wysiwyg("content"); ?>
<?php } ?>


This will result in editmode in this:

And in the frontend:

Advanced Usage

<?php while($this->block("contentblock")->loop()) { ?>
    <?php if($this->editmode) { ?>
        <?php echo $this->select("blocktype",array(
            "store" => array(
                array("wysiwyg", "WYSIWYG"),
                array("contentimages", "WYSIWYG with images"),
                array("video", "Video")
            ),
            "reload" => true
        )); ?>
    <?php } ?>
    
    <?php if(!$this->select("blocktype")->isEmpty()) {
        $this->template("content/blocks/".$this->select("blocktype")->getData().".php");
    } ?>
<?php } ?>

<?php while($this->block("teasers",array("limit" => 2))->loop()) { ?>
    <?php echo $this->snippet("teaser") ?>
<?php } ?>

Example for getCurrent()

<?php while ($this->block("myBlock")->loop()) { ?>
    <?php if ($this->block("myBlock")->getCurrent() > 0) { ?>
        Insert this line only after the first iteration<br />
        <br />
    <?php } ?>
    <h2><?php echo $this->input("subline"); ?></h2>
    
<?php } ?>

Using manual mode (since 1.4.5)

The manual mode offers you the possibility to deal with block the way you like, this is for example useful with tables: 

<?php $block = $this->block("gridblock", array("manual" => true))->start(); ?>
<table>
    <tr>
        <?php while ($block->loop()) { ?>
            <?php $block->blockConstruct(); ?>
                <td customAttribute="<?= $this->input("myInput")->getData() ?>">
                    <?php $block->blockStart(); ?>
                        <div style="width:200px; height:200px;border:1px solid black;">
                            <?php echo $this->input("myInput"); ?>
                        </div>
                    <?php $block->blockEnd(); ?>
                </td>
            <?php $block->blockDestruct(); ?>
        <?php } ?>
    </tr>
</table>
<?php $block->end(); ?>
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.