Think/Template.php
public function parse($content)
    {
        // 内容为空不解析
        if (empty($content)) {
            return '';
        }
        $begin = $this->config['taglib_begin'];
        $end = $this->config['taglib_end'];
        // 检查include标签
        $content = $this->parseInclude($content);
        // 检查PHP标签
        $content = $this->parsePhp($content);
        // 首先替换literal标签
        $content = preg_replace_callback(
            '/'.$begin.'literal'.$end.'(.*?)'.$begin.'\/literal'.$end.'/is',
            [$this, 'parseLiteral'],
            $content
        );

        // 内置标签库 不需使用标签库XML前缀
        $tagLibs = C('TAGLIB_BUILD_IN');
        /*
         * check if \Think\Template\TagLib\Cx::class is not loaded
         * \Think\Template\TagLib\Cx::class should load at last,
         * because other taglibs may depend on it,so push it at the
         * end of $tagLibs
         * @todo improve in future
         */
        if (!in_array(Cx::class, $tagLibs)) {
            array_push($tagLibs, Cx::class);
        }
        /**
         * @var $tag \Think\Template\TagLib
         */
        foreach ($tagLibs as $tag) {
            $this->parseTagLib(new $tag, $content);
        }

        //解析普通模板标签 {$tagName}
        return preg_replace_callback(
            '/('.$this->config['tmpl_begin'].')([^\d\w\s'.$this->config['tmpl_begin'].$this->config['tmpl_end'].'].+?)('.$this->config['tmpl_end'].')/is'
            ,
            [$this, 'parseTag'],
            $content
        );
    }
public function parse($content)
    {
        // 内容为空不解析
        if (empty($content)) {
            return '';
        }
        $begin = $this->config['taglib_begin'];
        $end = $this->config['taglib_end'];
        // 检查include标签
        $content = $this->parseInclude($content);
        // 检查PHP标签
        $content = $this->parsePhp($content);
        // 首先替换literal标签
        $content = preg_replace_callback(
            '/'.$begin.'literal'.$end.'(.*?)'.$begin.'\/literal'.$end.'/is',
            [$this, 'parseLiteral'],
            $content
        );

        // 内置标签库 不需使用标签库XML前缀
        $tagLibs = C('TAGLIB_BUILD_IN');
        /*
         * check if \Think\Template\TagLib\Cx::class is not loaded
         * \Think\Template\TagLib\Cx::class should load at last,
         * because other taglibs may depend on it,so push it at the
         * end of $tagLibs
         * @todo improve in future
         */
        if (!in_array(Cx::class, $tagLibs)) {
            array_push($tagLibs, Cx::class);
        }
        /**
         * @var $tag \Think\Template\TagLib
         */
        foreach ($tagLibs as $tag) {
            $this->parseTagLib(new $tag, $content);
        }

        //解析普通模板标签 {$tagName}
        return preg_replace_callback(
            '/('.$this->config['tmpl_begin'].')([^\d\w\s'.$this->config['tmpl_begin'].$this->config['tmpl_end'].'].+?)('.$this->config['tmpl_end'].')/is'
            ,
            [$this, 'parseTag'],
            $content
        );
    }
模板解析入口
支持普通标签和TagLib解析 支持自定义标签库

@param string $content 要解析的模板内容

@return string
@throws BaseException