@param \Twig_Template $scope
@param string         $name

@return mixed
355873
public function getUiPageSelf(\Twig_Template $scope, $name)
    {
        $file = $scope->getTemplateName();
        $pattern = '/ui\:(.*):(.*)\.html\.twig/';

        return preg_replace($pattern, sprintf('ui:$1:%s.html.twig', $name), $file);
    }
734842
public function getView($name)
    {
        if (!isset(self::$_controllers['view.'.$name])) {
            $view = $this->getController($name)->setView($name)->getView();
            self::$_controllers['view.'.$name] = $view;
        }

        return self::$_controllers['view.'.$name];
    }
1173306
function &get_template_vars($name=null)
	{
		if(!isset($name)) {
			return $this->_tpl_vars;
		} elseif(isset($this->_tpl_vars[$name])) {
			return $this->_tpl_vars[$name];
		} else {
			// var non-existant, return valid reference
			$_tmp = null;
			return $_tmp;
		}
	}
1162241
public   function getTemplate($name)
    {
          foreach($this->templates as $handler){
              
             if(is_string($handler)){
                 $template = $handler($name);
             }                             
             
              
              if(strlen($template) >0){
                  return $template;
              }
          }
    }
516519
private function compileClosureBlock(\Twig_Compiler $compiler, $parentName, $name)
    {
        $compiler
            ->addDebugInfo($this)
            ->write('$')->raw($name)->raw(' = ')
            ->raw('$this->env->getExtension(\'Fxp\Component\Block\Twig\Extension\BlockExtension\')->createNamed(')
            ->raw('\'Fxp\Component\Block\Extension\Core\Type\ClosureType\'')
            ->raw(', ')
            ->raw('array("data" => function ($blockView) use ($context, $blocks) { $this->block_')->raw($name)->raw('(array_merge($context, array(\'closure\' => $blockView)), $blocks); }')
            ->raw(', "block_name" => ')->string($name)->raw(', "label" => "")')
            ->raw(');')->raw("\n")
            ->write('$')->raw($parentName)->raw('Children[] = array(\'parent\' => $')->raw($parentName)->raw(', \'child\' => $')->raw($name)->raw(');')->raw("\n")
        ;
    }
265363
public function displayParentBlock($name, array $context, array $blocks = array())
    {
        $name = (string) $name;

        if (isset($this->traits[$name])) {
            $this->traits[$name][0]->displayBlock($name, $context, $blocks);
        } elseif (false !== $parent = $this->getParent($context)) {
            $parent->displayBlock($name, $context, $blocks);
        } else {
            throw new Twig_Error_Runtime(sprintf('The template has no parent and no traits defining the "%s" block', $name), -1, $this->getTemplateName());
        }
    }
1021843
static function laraform($name) {
        $el = new ElementSwitchTwbs($name);
        $el->addClass('js-bootstrap-switch')
            ->setOffClass('danger')
            ->setOffLabel('Нет')
            ->setOnClass('success')
            ->setOnLabel('Да')
            ->setSizeSmall();

        return $el;
    }
912711
private function searchBlock($blockName, Twig_Template $tpl)
    {
        // Current template might have parents, so we need to loop against
        // them to find a matching block
        do {
            foreach ($tpl->getBlocks() as $name => $block) {
                if ($name === $blockName) {
                    return $block;
                }
            }
        } while (($tpl = $tpl->getParent([])) instanceof Twig_Template);

        return null;
    }
587015
public function renderView(\Twig_Environment $env, $name, $route, array $params = [])
	{
		$config = $this->pm->getManagerConfig($name);
		$globals = $env->getGlobals();
		
		if (!isset($globals[self::TWIG_GLOBAL_VAR_NAME][$name])) {
			throw new \InvalidArgumentException(sprintf('The "%s" configuration key not found in twig global variables "%s".', $name, self::TWIG_GLOBAL_VAR_NAME));
		}
		
		return $env->render($config['template'], [
				'route' 		=> $route, 
				'params' 		=> $params,
				'managerName' 	=> $name,
				'context' 		=> $globals[self::TWIG_GLOBAL_VAR_NAME][$name]
		]);
	}
262715
public function supports($name)
    {
        if ($name instanceof Template) {
            return true;
        }

        $template = $this->parser->parse($name);

        return 'twig' === $template->get('engine');
    }
862516
public static function extend(BladeCompiler $blade, $name, $closure)
    {
        // For 5.0 after
        if (is_callable([$blade, 'directive'])) {
            $blade->directive($name, $closure);

            return;
        }

        // For 4.x before
        $blade->extend(
            function ($view, BladeCompiler $compiler) use ($name, $closure) {
                $pattern = $compiler->createMatcher($name);

                return preg_replace_callback(
                    $pattern,
                    function ($matches) use ($closure) {
                        if (empty($matches[2])) {
                            return $matches[0];
                        }

                        return $matches[1] . $closure($matches[2]);
                    },
                    $view
                );
            }
        );

        return;
    }
636108
public function findCached($scope, $name, $reversed)
	{
		$cacheKey = $this->makeCacheKey($scope, $name, $reversed);

		if (isset($this->cache[$cacheKey]))
		{
			return $this->cache[$cacheKey]['result'];
		}
	}
275546
public function callScopeFunction($name, ...$args)
    {
        if (is_string($name) && method_exists($this->model, $method = Str::camel('scope_'.$name))) {
            return $this->model->$method($this, ...$args);
        }

        if (is_callable($name)) {
            return tap($this, function () use ($name) {
                call_user_func($name, $this);
            });
        }

        throw new BadMethodCallException('Scope method could not be resolved: '.$method);
    }
11259
public function fetchTemplate(Request $request, $template)
    {
        if (!$this->view instanceof Twig) {
            throw new Exception("Twig provider not registered.");
        }

        foreach ($this->settings['view']['global'] as $key => $map) {
            $key = is_numeric($key) ? $map : $key;

            switch ($key) {
                case 'request':
                    $value = $request;
                    break;

                default:
                    $value = isset($this->container[$key]) ? $this->container[$key] : null;
                    break;
            }

            $this->view->getEnvironment()->addGlobal($map, $value);
        }

        $result = $this->view->fetch(
            $template . $this->settings['view']['extension'],
            $this->data->all()
        );

        return $result;
    }
999585
public function loadTemplate($name)
    {
        $template = new Template();
        $template->app = $this;

        if (in_array($name[0], ['.', '/', '\\']) || strpos($name, ':\\') !== false) {
            return $template->load($name);
        } else {
            $dir = is_array($this->template_dir) ? $this->template_dir : [$this->template_dir];
            foreach ($dir as $td) {
                if ($t = $template->tryLoad($td.'/'.$name)) {
                    return $t;
                }
            }
        }

        throw new Exception(['Can not find template file', 'name'=>$name, 'template_dir'=>$this->template_dir]);
    }
1352033
public function addTwigFunction($name, callable $function, array $options = [])
    {
        $twigfunction = new \Twig_SimpleFunction($name, $function, $options);

        $this->twig->addFunction($twigfunction);
    }
713630
public function templateEditAction(Request $request, $name)
    {
        $template_file_path = $this->get('kernel')->getBundle('SiteBundle')->getPath().'/Resources/views/'.$name.'.html.twig';

        if (!file_exists($template_file_path)) {
            return $this->redirectToRoute('cms_admin_appearance');
        }

        $template_code = file_get_contents($template_file_path);

        if ($request->isMethod('POST')) {
            $twig = $this->get('twig');

            $template_code = $request->request->get('template_code');

            try {
                $twig->parse($twig->tokenize($template_code));

                $twig->clearCacheFiles();

                $history = new AppearanceHistory();
                $history
                    ->setPath('/Resources/views/')
                    ->setFilename($name.'.html.twig')
                    ->setCode($template_code)
                    ->setUser($this->getUser())
                ;

                $this->persist($history, true);

                file_put_contents($template_file_path, $template_code);

                $this->addFlash('success', 'Шаблон обновлён.');

                return $this->redirectToRoute('cms_admin_appearance_template', ['name' => $name]);
            } catch (\Twig_Error_Syntax $e) {
                $this->addFlash('error', $e->getMessage());
            }
        }

        return $this->render('@CMS/AdminAppearance/template_edit.html.twig', [
            'name'          => $name,
            'templates'     => $this->getTemplates(),
            'template_code' => $template_code,
        ]);
    }