Git Product home page Git Product logo

Comments (11)

wisskid avatar wisskid commented on July 19, 2024

@Factify we could use a little bit more information. Maybe some sample code and the actual output vs expected output?

from smarty.

Factify avatar Factify commented on July 19, 2024

// load extension smarty class
require_once('mySmarty.extension.php');

use \Smarty{Smarty, Template};
use Factify\Classes{Hook, RunStatic};

class mySmarty extends Smarty {

/** __construct **/
public function __construct() {
    parent::__construct();

	
	$this->compile_check = false; 
    $this->force_compile = false; 
	
	/* The Smarty delimiter tags { and } will be ignored so long as they are surrounded
	by white space. This behavior can be disabled by setting auto_literal to false. */
	$this->auto_literal = true;
	
    // set compile root
	$this->setCompileDir('compile_tpl');
	
    // set root tpl||components
	$tempDirs['FTL'] = 'template_dir_1'; 
	$tempDirs['STL'] = 'template_dir_2'; 
	$tempDirs['MTL'] = 'template_dir_3'; 

	// set cache root
    $this->cache_dir = 'cache_tpl'; 
	
	// set configs root array
	$this->setConfigDir('config_tpl');
	
	// set Template Dir array
	$this->setTemplateDir($tempDirs);

	
    // Prefilter Before Compiled
	$this->registerFilter('pre', [$this, 'runFilterPre']);
	
	// outputfilter asfter Compiled 
	$this->registerFilter('output', [$this, 'runFilterOutput']);
	
	//#TDOD Handling missing templates || OLD => $this->_smarty_include
	$this->registerDefaultTemplateHandler([$this, 'handleMissingTemplate']);

    // add Extension
	$this->addExtension(new mySmartyExtension($this));

	// testInstall 
	//if(true === SD_DEBUG) $this->testInstall();
}

/*** Get Smarty object ***
* --> @return Smarty **/
//public function getSmarty() { return $this; }


public function ifExistRegistered($type = null, $name = null) {
	return (($type && $name) && isset($this->registered_plugins[$type][$name]));
}

public function handleMissingTemplate($type, $name, &$content, &$modified, Smarty $smarty) {		
	// return blank tpl
	return SD_TPL_ROOT_G . 'blank.tpl';
}
	
public function repFileName($name_file = '') {
	if(str_contains($name_file, ':')){
		if (($pos = strpos($name_file, ']')) !== false) $name_file = substr($name_file, $pos+1);
		if (($pos = strpos($name_file, ':')) !== false) $name_file = substr($name_file, $pos+1);
	}
	return $name_file;
}

/** ## Prefilter Before Compiled smarty output
 * @param string compiled content
 * --> @return string - transformed content **/
public function runFilterPre($tpl_output, Template $_template) {
	$file_dir = $_template->template_resource;
	if(!str_ends_with($file_dir, '.tpl')) return $tpl_output;
	
	//Remove HTML Comments
	$tpl_output = preg_replace('/<!--(.|\s)*?-->/', '', $tpl_output);
	
	$name_file = $this->repFileName($file_dir);
    Hook::load('smartyPreFetchHook', $tpl_output, $name_file);
	
	//@todo 
	$tpl_output = str_replace('xajax_', _PERFIX_REACT, $tpl_output);
	
	return $tpl_output;
}

/** ## transforms compiled smarty output
 * @param string compiled content
 * --> @return string - transformed content **/
public function runFilterOutput($tpl_output, Template $_template) {
	$file_dir = $_template->template_resource;
	if(!str_ends_with($file_dir, '.tpl')) return $tpl_output;
	
	$name_file = $this->repFileName($file_dir);
	echo ' <br>runFilterOutput name: ' . $name_file; // only for test
    Hook::load('smartyFetchHook', $tpl_output, $name_file);
	
    // static data class parser
    $tpl_output = RunStatic::collectJSDynamicCode($tpl_output, $name_file);			
	
	return $tpl_output;
}

}

//*** my mySmartyExtension file ***//
use Smarty\Extension\Base;

class mySmartyExtension extends Base {

/** __construct **/
public function __construct() {}

	
public function getModifierCallback(string $modifierName) {
	if(is_callable($modifierName)) return $modifierName;
	//#|TODO if(isset($this->functionCallback[$modifierName])) return $this->functionCallback[$modifierName];
	
	switch ($modifierName) {
		// #TODO
	}
	//if(is_callable($modifierName)) return $modifierName;
    return null;
}

}

from smarty.

wisskid avatar wisskid commented on July 19, 2024

@Factify found it, thanks for your bug report!

from smarty.

Factify avatar Factify commented on July 19, 2024

@wisskid I have tested, working only in fetch not on index.

from smarty.

wisskid avatar wisskid commented on July 19, 2024

Do you mean $smarty->display()?

from smarty.

Factify avatar Factify commented on July 19, 2024

@wisskid yes display.

from smarty.

wisskid avatar wisskid commented on July 19, 2024

There should be no difference between the two. Except maybe for already cached output. Can you try to empty your caches?

from smarty.

Factify avatar Factify commented on July 19, 2024

@wisskid I don't used the cache.

from smarty.

wisskid avatar wisskid commented on July 19, 2024

Strange. I've tested (and just retested) it using both $smarty->display('issue899.tpl'); and echo $smarty->fetch('issue899.tpl');. Result is the same, output filter is running perfectly. Please check if the error isn't in your own code, e.g. in the if(!str_ends_with($file_dir, '.tpl')) return $tpl_output; part.

If you're sure it's in Smarty, please provide a clear reproduction scenario. This issue is a great example on how to provide a reproduction scenario that will help us find the problem.

from smarty.

Factify avatar Factify commented on July 19, 2024

'public function runFilterOutput($tpl_output, Template $_template) {
$file_dir = $_template->template_resource;
if(!str_ends_with($file_dir, '.tpl')) return $tpl_output;

echo ' <br>runFilterOutput name: ' . $file_dir; // only for test	

return $tpl_output;

}'

from smarty.

Factify avatar Factify commented on July 19, 2024

@wisskid Now in my project I have smarty version 4.3.2 .output filter is OK.

from smarty.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.