Transform the template to code
that can be used independently

@param bool $layout Whether to use the layout or raw code

@return string
764162
public function compile($layout = true)
    {
        $code = $this->trim($this->source);
        $buffer = '';
        $open = array();
        
        Tokenizer::i($code)->tokenize(function ($node) use (&$buffer, &$open) {
            switch ($node['type']) {
                case Tokenizer::TYPE_TEXT:
                    $buffer .= $this->generateText($node, $open);
                    break;
                case Tokenizer::TYPE_VARIABLE_ESCAPE:
                    $buffer .= $this->generateEscape($node, $open);
                    break;
                case Tokenizer::TYPE_VARIABLE_UNESCAPE:
                    $buffer .= $this->generateVariable($node, $open);
                    break;
                case Tokenizer::TYPE_SECTION_OPEN:
                    $buffer .= $this->generateOpen($node, $open);
                    break;
                case Tokenizer::TYPE_SECTION_CLOSE:
                    $buffer .= $this->generateClose($node, $open);
                    break;
            }
        });
        
        //START: This is more to help troubleshooting
        if (count($open)) {
            foreach ($open as $i => $item) {
                $open[$i] = sprintf(self::ERROR_LINE, $item['value'], $item['line']);
            }

            throw new Exception(sprintf(self::ERROR_MISSING_CLOSING, implode(self::ERROR_AND, $open)));
        }
        //END: This is more to help troubleshooting
        
        if (!$layout) {
            return $buffer;
        }

        return sprintf(self::$layout, $buffer);
    }
126809
public static function beginFormTb(
        $layout = self::FORM_LAYOUT_VERTICAL,
        $action = '',
        $method = 'post',
        $htmlOptions = array()
    ) {
        if (!empty($layout)) {
            // refactor to not use a switch
            switch ($layout) {
                case self::FORM_LAYOUT_HORIZONTAL:
                    self::addCssClass('form-' . self::FORM_LAYOUT_HORIZONTAL, $htmlOptions);
                    break;
                case self::FORM_LAYOUT_INLINE:
                case self::FORM_LAYOUT_SEARCH:
                    self::addCssClass('form-' . self::FORM_LAYOUT_INLINE, $htmlOptions);
                    break;
                default:
                    self::addCssClass('form-' . $layout, $htmlOptions);
            }
        }
        return parent::beginForm($action, $method, $htmlOptions);
    }
123481
protected static function compile_layouts($value)
	{
		// If the Blade template is not using "layouts", we'll just return it
		// unchanged since there is nothing to do with layouts and we will
		// just let the other Blade compilers handle the rest.
		if ( ! starts_with($value, '@layout'))
		{
			return $value;
		}

		// First we'll split out the lines of the template so we can get the
		// layout from the top of the template. By convention it must be
		// located on the first line of the template contents.
		$lines = preg_split("/(\r?\n)/", $value);

		$pattern = static::matcher('layout');

		$lines[] = preg_replace($pattern, '$1@include$2', $lines[0]);

		// We will add a "render" statement to the end of the templates and
		// then slice off the "@layout" shortcut from the start so the
		// sections register before the parent template renders.
		return implode(CRLF, array_slice($lines, 1));
	}
60509
public function setLayout($layout)
	{
		if (strpos($layout, ':') === false)
		{
			$this->_layout = $layout;
		}
		else
		{
			// Convert parameter to array based on :
			$temp = explode(':', $layout);
			$this->_layout = $temp[1];

			// Set layout template
			$this->_layoutTemplate = $temp[0];
		}

		return $this;
	}
1202640
public function getLayoutFromTemplate($template)
	{
	    $content = file_get_contents($this->getTemplateFile($template));
	    
	    return $this->getEngineInstance()->getLayout($content);
	}
786940
protected static function processSetLayout($html){
    $pattern = '~<p>LAYOUT:([\w_-]+):TUOYAL<\/p>~m';
    if( preg_match_all($pattern, $html, $matches, PREG_SET_ORDER) ){
      $layout = array_pop($matches);

      self::setLayout($layout[1]);

      $html = preg_replace($pattern, '', $html);
    }
    return $html;
  }
1131115
public function renderSelf($layout = null, $title = null)
    {
        return $this->renderTag($this->renderContainer($layout, $title));
    }
1266058
private function createRootPage($site, $layout)
    {
        $pagebuilder = $this->bbapp->getContainer()->get('pagebuilder');
        $pagebuilder
            ->setUid(md5('root-' . $site->getLabel()))
            ->setTitle('Home')
            ->setLayout($layout)
            ->setSite($site)
            ->setUrl('/')
            ->putOnlineAndHidden()
        ;

        $page = $pagebuilder->getPage();
        $this->entyMgr->persist($page);
        $this->entyMgr->flush($page);

        return $page;
    }
765907
protected function validateLayoutStyles(array $layout)
    {
        if (isset($layout[static::PADDING_TOP])
            && (0 > $layout[static::PADDING_TOP] || 300 < $layout[static::PADDING_TOP])
        ) {
            throw new InvalidArgumentException('Invalid layout padding top');
        }

        if (isset($layout[static::PADDING_BOTTOM])
            && (0 > $layout[static::PADDING_BOTTOM] || 300 < $layout[static::PADDING_BOTTOM])
        ) {
            throw new InvalidArgumentException('Invalid layout padding bottom');
        }
    }
1277358
public function qualifyLayout($layout, $type = 'com')
    {
        $layout = (string) $layout;

        //Handle partial layout paths
        if(!parse_url($layout, PHP_URL_SCHEME))
        {
            $package = $this->getIdentifier()->package;
            $domain  = $this->getIdentifier()->domain;
            $format  = $this->getFormat();

            $path = $this->getIdentifier()->getPath();
            array_shift($path); //remove 'view'
            $path[] = basename($layout);

            $path = implode('/', $path);

            if($domain) {
                $layout = $type.'://'.$domain .'/' . $package . '/' .$path;
            } else {
                $layout = $type.':' . $package . '/' .$path;
            }

            $layout = $layout.'.'.$format;
        }

        return $layout;
    }
212728
public function renderContent($layout = null, $title = null)
    {
        if ($this->hasSourceComponent()) {
            return $this->SourceComponent()->renderContent($layout, $title);
        }
        
        return parent::renderContent($layout, $title);
    }
361727
public function renderSelf($layout = null, $title = null)
    {
        return $this->getController()->customise([
            'Content' => $this->renderContent($layout, $title)
        ])->renderWith(self::class);
    }
655243
public function getCoreRenderedTemplate( $template, $layout = NULL ) {
        return $this->render(POWERON_ROOT . DS . $template, $layout ? POWERON_ROOT . DS . $layout : NULL);
    }
496260
public function layout()
    {
        $exists = (boolean) isset($this->data['layout']);

        return $exists ? $this->data['layout'] : null;
    }
620539
public function makeViewContent($contents, $layout = null)
    {
        if ($this->suppressLayout || $this->layout == '') {
            return $contents;
        }

        // Append any undefined block content to the body block
        Block::set('undefinedBlock', $contents);
        Block::append('body', Block::get('undefinedBlock'));
        return $this->makeLayout($layout);
    }
925316
public static function translateLayout(LayoutInterface $template, $locale, TranslatorInterface $translator = null)
    {
        if (null === $template->getTranslationDomain()) {
            $template = $template->getTranslation($locale);
        } elseif (null !== $translator) {
            static::injectTranslatorValues($translator, $template);
        }

        return $template;
    }
950470
public function updateLayout(Layout $layout)
    {
        if (null === $layout->getSite()) {
            return false;
        }

        $layoutfile = $this->getLayoutFile($layout);
        File::resolveFilepath($layoutfile, null, array('include_path' => $this->_layoutdir));

        if (false === file_exists($layoutfile)) {
            File::resolveFilepath($layoutfile, null, array('base_dir' => $this->_layoutdir[1]));
        }

        if (false === file_exists($layoutfile) && false === touch($layoutfile)) {
            throw new RendererException(sprintf('Unable to create file %s.', $layoutfile), RendererException::LAYOUT_ERROR);
        }

        if (!is_writable($layoutfile)) {
            throw new RendererException(sprintf('Unable to open file %s in writing mode.', $layoutfile), RendererException::LAYOUT_ERROR);
        }

        return $layoutfile;
    }