Basecoat\View::parseBlocks PHP Method

parseBlocks() public method

Parse a template into content block namespaces if content block identifiers are present
public parseBlocks ( String $tpl ) : integer
$tpl String template to parse
return integer number of content blocks discovered
    public function parseBlocks($tpl)
    {
        $tpl_blocks = preg_split($this->block_tag_regex, ltrim($tpl), -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
        $blocks_parsed = count($tpl_blocks);
        if (1 == $blocks_parsed) {
            $this->addBlock($this->default_namespace, $tpl_blocks[0]);
        } else {
            $blocks_parsed = $blocks_parsed / 2;
            $namespace = $this->default_namespace;
            foreach ($tpl_blocks as $i => $data) {
                if ($i % 2 == 0) {
                    if (strlen($data) > 30) {
                        $this->addBlock($namespace, $data);
                    } else {
                        $namespace = $data;
                    }
                } else {
                    $this->addBlock($namespace, $data);
                }
            }
        }
        return $blocks_parsed;
    }