Comments (11)
@Factify we could use a little bit more information. Maybe some sample code and the actual output vs expected output?
from smarty.
// 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.
@Factify found it, thanks for your bug report!
from smarty.
@wisskid I have tested, working only in fetch not on index.
from smarty.
Do you mean $smarty->display()
?
from smarty.
@wisskid yes display.
from smarty.
There should be no difference between the two. Except maybe for already cached output. Can you try to empty your caches?
from smarty.
@wisskid I don't used the cache.
from smarty.
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.
'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.
@wisskid Now in my project I have smarty version 4.3.2 .output filter is OK.
from smarty.
Related Issues (20)
- Fatal error: Uncaught --> Smarty: Unable to write file [file_path] thrown in C:\[project_path]\vendor\smarty\smarty\src\Smarty.php on line 1732 HOT 7
- Request for `prependTemplateDir()` or more options with `addTemplateDir()` - weight, duplicate handling HOT 9
- undefined extension class 'Smarty_Internal_Method_Get_Template_Vars' HOT 1
- Is it possible patch v2 for PHP8 instead of migrating to v4+? HOT 1
- default modifier ignores nocache on variables
- Smarty registered classes check prevents use of class constants to avoid typo bugs in templates HOT 2
- 4.5.3: Function whitelist via Smarty_Security is being ignored
- Misleading error messages with {capture}
- Smarty v5 Error: {section} Tag First Argument Type Mismatch when opening and closing tag on NoCache HOT 3
- Help with Smarty dateformat modifier - change to dd/mm/yyyy HOT 5
- Error: For loop not working when using extends resource type HOT 1
- Smarty Not Working HOT 3
- XAXOKPIMUE
- How to use '|' as '||'? HOT 1
- How it's possible to modifiy tpl_vars subkey inside a plugin function HOT 3
- Feature request. Able to run multiple versions HOT 4
- how to use loadFilter() ? HOT 5
- Unable to override built-in modifiers. HOT 3
- unknown modifier 'var_dump' and unknown modifier 'print_r' HOT 1
- Composer and external dependencies defeat the point of using Smarty over any off-the-shelf framework. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from smarty.