Changeset 430

Show
Ignore:
Timestamp:
04/30/07 16:16:17 (2 years ago)
Author:
laurentj
Message:

improved jtpl : allow to specify our own format type

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix/core/jSelector.class.php

    r427 r430  
    533533    protected $_suffix = '.tpl'; 
    534534    protected $_where; 
    535  
    536     function __construct($sel){ 
     535    public $outputType=''; 
     536 
     537    /** 
     538     * @param string $sel the template selector 
     539     * @param string $outputtype  the type of output (html, text..) By default, it take the response type 
     540     */ 
     541    function __construct($sel, $outputtype=''){ 
     542        if($outputtype == '') 
     543            $this->outputType = $GLOBALS['gJCoord']->response->getFormatType(); 
     544        else 
     545            $this->outputType = $outputtype; 
     546 
    537547        $this->_compiler='jTplCompiler'; 
    538548        $this->_compilerPath=JELIX_LIB_TPL_PATH.'jTplCompiler.class.php'; 
  • trunk/lib/jelix/tpl/jTpl.class.php

    r411 r430  
    162162     * @param string $fctname the internal function name (meta or content) 
    163163     */ 
    164     protected function  getTemplate($tpl,$fctname){ 
     164    protected function  getTemplate($tpl,$fctname, $outputtype=''){ 
    165165#ifnot JTPL_STANDALONE 
    166         $sel = new jSelectorTpl($tpl); 
     166        $sel = new jSelectorTpl($tpl,$outputtype); 
    167167        jIncluder::inc($sel); 
    168168        $fct = $fctname.md5($sel->module.'_'.$sel->resource); 
     
    183183 
    184184            $compiler = new jTplCompiler(); 
    185             $compiler->compile($tpl); 
     185            $compiler->compile($tpl,$outputtype); 
    186186        } 
    187187        require_once($cachefile); 
     
    194194     * return the generated content from the given template 
    195195     * @param string $tpl template selector 
     196     * @param string $outputtype 
    196197     * @return string the generated content 
    197198     */ 
    198     public function fetch ($tpl){ 
     199    public function fetch ($tpl, $outputtype=''){ 
    199200        ob_start (); 
    200201        try{ 
    201            $this->getTemplate($tpl,'template_'); 
     202           $this->getTemplate($tpl,'template_', $outputtype); 
    202203           $content = ob_get_clean(); 
    203204        }catch(Exception $e){ 
  • trunk/lib/jelix/tpl/jTplCompiler.class.php

    r415 r430  
    6262    private $_sourceFile; 
    6363    private $_currentTag; 
     64    private $_outputType; 
    6465 
    6566    /** 
     
    8788     * @return boolean true if ok 
    8889     */ 
    89     public function compile($tplFile){ 
     90    public function compile($tplFile, $outputtype){ 
    9091        $this->_sourceFile = $tplFile; 
    9192        $cachefile = JTPL_CACHE_PATH . basename($tplFile); 
    92  
     93        $this->_outputType = ($outputtype==''?'html':$outputtype); 
    9394#else 
    9495    /** 
     
    102103        $this->_sourceFile = $selector->getPath(); 
    103104        $cachefile = $selector->getCompiledFilePath(); 
    104  
     105        $this->_outputType = $selector->outputType; 
    105106        jContext::push($selector->module); 
    106107#endif 
     
    502503     */ 
    503504    protected function _getPlugin($type, $name){ 
    504 #if JTPL_STANDALONE 
    505         $treq = 'html'; 
    506 #else 
    507         global $gJCoord, $gJConfig; 
    508         $treq = $gJCoord->response->getFormatType(); 
    509 #endif 
    510505        $foundPath=''; 
    511506 
    512507#if JTPL_STANDALONE 
    513         if(isset($GLOBALS['jTplConfig']['tplpluginsPathList'][$treq])){ 
    514             foreach($GLOBALS['jTplConfig']['tplpluginsPathList'][$treq] as $path){ 
    515 #else 
    516         if(isset($gJConfig->{'_tplpluginsPathList_'.$treq})){ 
    517             foreach($gJConfig->{'_tplpluginsPathList_'.$treq} as $path){ 
     508        if(isset($GLOBALS['jTplConfig']['tplpluginsPathList'][$this->_outputType])){ 
     509            foreach($GLOBALS['jTplConfig']['tplpluginsPathList'][$this->_outputType] as $path){ 
     510#else 
     511        global $gJConfig; 
     512        if(isset($gJConfig->{'_tplpluginsPathList_'.$this->_outputType})){ 
     513            foreach($gJConfig->{'_tplpluginsPathList_'.$this->_outputType} as $path){ 
    518514#endif 
    519515                $foundPath=$path.$type.'.'.$name.'.php'; 
Download in other formats: Unified Diff Zip Archive