Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

eval smarty code is good way ?
Goto page Previous  1, 2
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
sm@rty
Smarty Regular


Joined: 01 Oct 2014
Posts: 65

PostPosted: Mon Mar 09, 2015 6:14 pm    Post subject: Reply with quote

ah but problem is exists !

my plugin code (compiler.require.php) :

Code:

<?php
class Smarty_Compiler_require extends Smarty_Internal_Compile_Include
   {
      public $required_attributes = array('file');
      public $shorttag_order = array('file');
      public $option_flags = array('nocache', 'inline', 'caching');
      public $optional_attributes = array('compile_id', 'scope');

      public function compile($args, Smarty_Internal_SmartyTemplateCompiler $compiler, $parameter = null)
         {
            $_attr = $this->getAttributes($compiler, $args);
            $newArgs = array();
            $newArgs[0]['file'] = "'mysql:'.".$_attr['file'];
            $newArgs[]['compile_id'] = "'{$GLOBALS['user_id']}'";
            $newArgs[]['scope'] = "'parent'";
            return parent::compile($newArgs, $compiler, $parameter);
         }
   }
?>



smarty code :

tpl main :
Code:

{require 'test'}
{$b}

tpl test :
Code:
{$b='var1'}
test loaded


output :

Code:
test loaded


smarty php code output (cache) :

Code:
echo $_smarty_tpl->getSubTemplate ('mysql:'.'test', $_smarty_tpl->cache_id, '24', 1, $_smarty_tpl->cache_lifetime, array(), 1);


$b not be echo in scope parent !
where is the problem ?
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Mar 10, 2015 4:18 pm    Post subject: Reply with quote

When you use a variable template name in {include} or your {require} the template can not be cached in the main cache file and Smarty will create an individual cache file. This will be called in nocache mode.

There are now 2 problems.
As 'test' is called as separate cache file it does not assign $b unless you change it to {$b='var1' nocache}

As {$b} is now assigned in nocache mode in 'main' it must be {$b nocache}


You have made the change in a way that the compiler always thinks it's a variable name.

Use "'mysql:'.".$_attr['file'] only of $_attr['file'] does contain '$'.
Back to top
View user's profile Send private message
sm@rty
Smarty Regular


Joined: 01 Oct 2014
Posts: 65

PostPosted: Tue Mar 10, 2015 6:12 pm    Post subject: Reply with quote

Quote:
When you use a variable template name in {include} or your {require} the template can not be cached in the main cache file and Smarty will create an individual cache file. This will be called in nocache mode.

There are now 2 problems.
As 'test' is called as separate cache file it does not assign $b unless you change it to {$b='var1' nocache}

As {$b} is now assigned in nocache mode in 'main' it must be {$b nocache}


ok.

Quote:
You have made the change in a way that the compiler always thinks it's a variable name.

Use "'mysql:'.".$_attr['file'] only of $_attr['file'] does contain '$'.


but i tested.

for example :

Code:
{require 'tpl'}
{require $var}


the examples works.

thanks u-tews.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP