/** * explicitly insert template at $blockName position * * @param SimpleTemplate $childTemplate * @param string $blockName * @return SimpleTemplate */ public function insertTemplateAt(SimpleTemplate $childTemplate, $blockName) { $blockRegExp = '~<!--\\s*\\{\\s*block\\s*:\\s*' . $blockName . '\\s*\\}\\s*-->~'; if (preg_match($blockRegExp, $this->rawContents)) { $this->rawContents = preg_replace($blockRegExp, $childTemplate->getRawContents(), $this->rawContents); } else { throw new SimpleTemplateException("Could not insert child template at '{$blockName}'.", SimpleTemplateException::TEMPLATE_INVALID_NESTING); } return $this; }