Using Naneau_View_Smarty with RC1
by Naneau
The new viewRenderer, introduced with the Zend Framework 1.0.0RC1 is a source of confusion for a lot of us. When I first upgraded I couldn’t figure out what on earth it was trying to do. Luckily, Matthew Weier O’Phinney has written an article over on devzone that explains the basics of it. I now understand the idea behind it and I am convinced that it can be handy. The migration guide also has some good tips.
Whether or not it should be enabled by default is another matter though. There have been quite a few debates over at #zftalk about how it breaks compatibility with pretty much everything. While this is to be expected in the days before 1.0, it would have been nice to not have to disable it to get your scripts to work.
At any rate. A while ago I wrote about using Smarty with the Zend Framework. While my implementation was solid and easy, it will not work with the viewRenderer. First of all, it relied on manually rendering the view, not using $this->render() from your controllers. That is now considered obsolete.
So, how do you get it to work then? Well, you have to tell viewRenderer to use Naneau_View_Smarty, and maybe tell it to search for files with a .tpl extension (that’s not required, but Smarty template files traditionally end in .tpl). In your bootstrap you can do this like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | /** * Naneau_View_Smarty */ require_once 'Naneau/View/Smarty.php'; $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer(); $viewRenderer->setView(new Naneau_View_Smarty(array( 'compileDir' => COMPILE_DIR) //replace COMPILE_DIR with a directory your webserver has write access to )); //make viewRenderer use Naneau_View_Smarty $viewRenderer->setViewSuffix('tpl'); //make it search for .tpl files Zend_Controller_Action_HelperBroker::addHelper($viewRenderer); //add it to the action helper broker |
That should do it for the setup. Now, I have also made a tiny change to Naneau_View_Helper, to allow viewRenderer to tell it where to look for templates. This was suggested by Ralph Schindler, and I’m happy he did, because it made the code a bit shorter. I scrapped the setScriptPath() method and updated the _run() to:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | /** * fetch a template, echos the result, * * @see Zend_View_Abstract::render() * @param string $name the template * @return void */ protected function _run() { $this->strictVars(true); $vars = get_object_vars($this); foreach ($vars as $key => $value) { if ('_' != substr($key, 0, 1)) { $this->_smarty->assign($key, $value); } } //assign variables to the template engine $this->_smarty->assign_by_ref('this', $this); //why 'this'? //to emulate standard zend view functionality //doesn't mess up smarty in any way $path = $this->getScriptPaths(); $file = substr(func_get_arg(0), strlen($path[0])); //smarty needs a template_dir, and can only use templates, //found in that directory, so we have to strip it from the filename $this->_smarty->template_dir = $path[0]; //set the template diretory as the first directory from the path echo $this->_smarty->fetch($file); //process the template (and filter the output) } |
At any rate, download Naneau_View_Smarty 0.2 and check it out.
Comments
How do you handle things like {include file=”header.tpl”} in your smarty templates using this method? header.tpl is just another static template.
Thanks.
-Justin
Hi!
Tried your approach, and i can tell you it ROCKS!
I’ve extended smarty object with some pre and output filters(removeHTMLComments, trimWhiteSpace, Gzip …) everything is ZF compatible eg: replacing header() functions with $front->getResponse()->setHeader() …
I add In front controller this code:
$viewRenderer->setViewScriptPathSpec(‘:module/:controller/:action.:suffix’);
so it’s very easy to include other templates …
{include file=’default/index/header.tpl’}
Awesome!
Regards,
AlesL
Justin, what you’re trying to do will be considered obsolete once Zend_Layout is done. Which should be soon. You would be better of using a two-step-view approach, like described here: http://blog.astrumfutura.com/archives/288-Complex-Views-with-the-Zend-Framework-Part-5-The-Two-Step-View-Pattern.html
Though I must admit that I find this approach a bit complicated, you may also want to check out:
http://framework.zend.com/wiki/display/ZFMLGEN/mail/27145
I think i have a little problem , how to get this working with the view renderer ?
See the first code example. You have to tell viewRenderer that you want it to use Naneau_View_Smarty.
This seems like a really promising extension to Zend_Framework, if I could only get it to work… There are some ambiguities in the setup description which perhaps Naneau could clarify? In particular I don’t see an documentation on exactly how to render or display the Smarty templates from within your controller classes.
Am I correct in assuming that a complete bootstrap (which should presumably come after the Zend_Controller_Front::run(‘/path/to/controllers/’) call in the file html/index.php) would be:
//——–
// array defining smarty script paths
$smartyPaths = array(
’scriptPath’ => ‘/path/to/templates/’,
‘compileDir’ => ‘/path/to/templates_c/’,
‘configDir’ => ‘/path/to/configs/’);
// make ViewRenderer helper which uses Naneau_View_Smarty
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
$viewRenderer->setView(new Naneau_View_Smarty(array($smartyPaths)));
// make it search for .tpl files
$viewRenderer->setViewSuffix(‘tpl’);
// add it to the action helper broker
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
//——–
And exactly what syntax should be used to set variables and render or display templates in the controller classes? Given a typical controller structure,
class SomeController extends Zend_Controller_Action {
public function someAction(){
// set Smarty variables and render templates here
}
}
would you use the typical ViewRenderer syntax:
$this->view->name = ‘Ned’;
$this->display(‘index.tpl’);
to define a variable which is included in ‘index.tpl’ in the ’scriptPath’ directory as {$name}? This doesn’t work for me. Or would you use the typical smarty syntax:
$this->assign(‘name’,'Ponkey’);
$this->display(‘index.tpl’);
Or is it neither of these, and if so what? Instantiate another Smarty object? Somehow make a call on Smarty object instantiated in the bootstrap using the Naneau_View_Smarty getEngine() method?
And assuming that there are two directories which you can access from the controller class (the Smarty template directory and applications/views/scripts/controllerName), where can you put .tpl files and are you not able to use {$smarty} variables in your view scripts? I don’t see anything on this either, and it is a little ambiguous.
Please advise… Looks awesome if I could just get it to run.
Dave
okay, in your order:
you try to set up the smarty view with a double array. Also, you don’t have to specify the scriptPath anymore, viewRenderer will find that for you.
You can access the view, once you have set it in the viewRenderer action helper, in your controllers with $this->view . You don’t have to render it manually, viewRenderer will do that for you, and find the correct template. If you want to change the template it uses, use $this->render(’someOtherTemplate’); You can’t use smarty’s display function directly, it gets called from within Naneau_View_Smarty. If you really must use retrieve smarty object use $this->view->getEngine()
You can assign variables to it using the regular zend view syntaxt, so:
$this->view->someVar = ’someValue’;
You should put the template files in a directory called ’scripts’, which should be located under ‘views’ of the module you are using. See: http://naneau.nl/2007/06/03/on-modules/ for more info on directory layouts.
Hope this helps you on your way!
I have a weird problem with the Smary implementation in RC1. Everything works fine but i have a problem fetching the content of a template when i do the following in my indexAction:
$test = $this->render(‘index’);
var_dump($test);
=> the result is NULL
When i remove the lines or when i just do $this->render(‘index’) the template is correctly shown with all the content.
Also when i change the the render to this: $this->render(‘test’); it works. This is proof that the function gets called. $test = $this->render(‘test’); fails because $test = Null.
I trace everything back to the abstract view class. The function render there does this:
$this->_file = $this->_script($name);
unset($name); // remove $name from local scope
ob_start();
$this->_run($this->_file);
return $this->_filter(ob_get_clean()); // filter output
When i echo the result of $this->_filter(ob_get_clean()); i see the content so it should return it.
I don’t understand how the result of the render() is not correctly returned.
I have this in my bootstrap:
$Lview_obj = new SN_Zend_View_Smarty($Lconfig_obj->zend->view->asArray());
$LviewRenderer_obj = new Zend_Controller_Action_Helper_ViewRenderer($Lview_obj);
$LviewRenderer_obj->setViewSuffix(‘tpl’);
$LviewRenderer_obj->setViewScriptPathSpec(‘:controller:action.:suffix’); // used as default
Zend_Controller_Action_HelperBroker::addHelper($LviewRenderer_obj); // Add it to the action helper broker
Any suggestion where the problem lies ?
You don’t have a problem
. I actually tried what you are doing myself, a long time ago. The render() method doesn’t return it’s output as a string. In fact, it appends it to the body of the response. If you must get the rendered template as a string, I suggest you use:
$this->getResponse()->getBody()
Thanks Naneau,
Thanks for the hints, but more confused than ever:
In the documentation for your current (0.2) version of Smarty.php you write:
* Pass it a an array with the following configuration options:
*
* scriptPath: the directory where your templates reside
* compileDir: the directory where you want your compiled templates (must be
* writable by the webserver)
* configDir: the directory where your configuration files reside
*
* both scriptPath and compileDir are mandatory options, as Smarty needs
* them. You can’t set a cacheDir, if you want caching use Zend_Cache
* instead, adding caching to the view explicitly would alter behaviour
* from Zend_View.
From your response I gather that this is out of date, and the ViewRenderer will expect to find scripts with Smarty variables in your application/views/scripts/controller_name folders, not in any scriptPath passed in an array. Note that you never explicitly say this in any of your posts, and directly contradict it in your documentation!
In your first example the Naneau_View_Smarty array signature was written like this:
$viewRenderer->setView(new Naneau_View_Smarty(array(‘compileDir’ => TEMP_DIR)));
When you write that I am trying to set up Smarty with a double array, I’m not sure what you mean (multi-dimensional array – no?; passed two arrays – no?, array passed twice – no?). As far as I can tell from your documentation, I am supposed to pass this array to Naneau_View_Smarty in the bootstrap code, and only in the bootstrap code, and it should include ‘compileDir’ and ‘configDir’ keys. Your constructor is set up to throw an exception if it doesn’t get the ‘compileDir’ and ‘configDir’ keys. As far as I can tell I am only supposed to pass this array and instantiate a Naneau_View_Smarty object in my bootstrap code, correct?
I have tried putting Smarty variables such as {$testName} in fileName.phtml and fileName.tpl files in my ‘views/scripts/controller_name’ folder, and then calling $this->render(‘fileName’) after defining a variable using $this->view->someVariable = ’someValue’. The fileName.phtml files render fine except for the Smarty variables. The fileName.tpl files do not render, but throw the following exception:
message ’script ‘collections/fileName.phtml’ not found in path’
Clearly the ViewRenderer is only looking for .phtml files, not .tpl.
My Naneau_View_Smarty bootstrap code comes after my front controller static call:
Zend_Controller_Front::run(‘../application/controllers/’);
If I put it before, it breaks everything – is there a problem with where it is? Is there a place it belongs other than after Zend_Controller_Front?
Your comment that ‘You can access the view, once you have set it in the viewRenderer action helper, in your controllers with $this->view’ gives me that feeling that there might be some other steps in the controller classes which are not documented, or which are out-of-date in the documentation. Are you referring to the action helper setup in the bootstrap code, or undocumented calls one is supposed to make to the Zend_Controller_Action_HelperBroker in the controller classes?
Given the issues with the documentation, how about pasting a fresh example of the bootstrap code with an example array being passed? If there is any additional code needed in the controller classes other than $this->view->someVariable = ’someValue’ and $this->render(‘fileName’), I would appreciate it if you could paste that as well.
Thanks,
Dave
Okay i got it now, 2 Questions left.
What is the config_dir for , why is it needed ?
And Second how to cache thoose smarty stuff with zend cache ?
Thx Christian
The config dir is optional. If you do not know what it does, just don’t use it. If you must know what it does: http://smarty.php.net/manual/en/config.files.php
About the problem i mentioned above I found a solution for it.
Instead of using $this->render(‘index’) => manual of automatic you can use $content = $this->renderScript(‘index’); This also does the thing i wanted.
I am also wondering why there is so much information about using a two step view process. When you use smarty you can use the include statements to include footers and headers and with capture blocks you can also define a layout. Or is there more to it ?
The only thing i have not figured out yet is a way to call other actions (same of other controller) and capture their output that you can use in your current action. I have seen an implementation with a widget function that calls the frontcontroller agian but that wasn’t a good solution. Is there a clean way of doing this in the current version of the framework or do i have to wait when zend_layout comes. I believe that in the proposal of zend_layout that issue was addressed or am i wrong ?
Hi!
Thank you for this smart implementation that keeps ZF view rendring mecanisme running as transparent as possible.
Naneau_View_Smarty class save my life
Howevere I would like to try to let the designer make the choice whether to go with smarty or with an another engine (Zend_View). The front controller (or other composant) must be able to fetch the list of available “action.ext” files in module/scripts/controller folder before it assigns the view to the relevant “.ext” engine.
In this logic, Zend_View will focus on “.phtml” files and Smarty will see only “.tpl” file.
Combining the two worlds will be benefits when displaying views that are forwarded through different controller/actions.
Any idea how to implement this without re inventing the wheele?
Thanks!
Try putting it in the view. Try to figure out what’s required in the _run() method. If it’s a smarty file, use smarty, otherwise, just use the parent::_run() method. It may not be the prettiest solution, but it’s easy to set up.
Effectively, it is one possible solution. It’s possible to use an activateEngine($eng) funtion in actionController() that switch between Zend_View or Naneau_View_Smarty.
I prefere to extend Zend_View rather than Zend_View_Abstract because the parent::_run() is an abstract (empty) function and we can’t call it.
so what we can add to achieve this :
//set the default engine here (possible values are zend or smarty)
$protected $_activeEngine = “zend”;
public function activateEngine($engName=”zend”){
$_activeEngine = $engName;
}
protected function _run(){
switch ($_activeEngine){
case “smarty” :
//the code of _run in current Naneau_View_Smarty::_run() go here
break;
case “zend” :
parent::_run(func_get_arg(0));
}
}
now we don’t need to specify “.tpl” extension (smart is able to handel any extension), we need only to
add a line in actionController() :
$this->view->activateEngine(“smarty”);
Or
$this->view->activateEngine(“zend”);
Remarks :
May be we need also to construct the smarty engine later (not in class::__construct() ) and only if called in getEngine() to avoid to load the class when it will never be used and in _run() function we refere to it by $this->getEngine()
Think also to collect all diffrent engines in an array ($_listEngine ) with keys = “zend”, “smarty” ..
Sounds like a decent enough implementation to me! I’m still a bit torn on the ‘we want to support two templating engines’, but if you have a valid enough reason to do that it’s fine.
In CMS perspective, you need to have many templating engines
David Johnson: You are absolutely right. I’m sorry for replying this late, your comment got held up by Akismet. I’ll write a new example soon and put it up. Im sorry for leaving in outdated documentation in the file, I’ll address that ASAP too.
You do have to set up the viewRenderer action helper before you let the front controller do it’s work (doing run()). If it gives you problems if you put it before the run() statement, please tell me about those, I’m sure it’s something trivial. The documentation in the file is a bit out of date, the only configuration statement you have to pass to it is a compileDir. You have to do that in a associative array, like array(‘compileDir’ => ‘/some/dir’).
At any rate. I write this blog as something of a hobby. Some things on it may not make sense / be outdated quickly. Especially the stuff related to the Zend Framework has this problem, as the framework evolves fast. I hang out a lot on #zftalk on freenode (IRC), feel free to look for me there, if I’m not there personally, there’s a good chance someone else can help you out.
[...] Naneau » Using Naneau_View_Smarty with RC1 (tags: smarty zend) [...]
Hey,
I can’t get Naneau_View_Smarty working. I’m new to ZF so a more detailed example of usage would be helpful.
Thanx
Jeff
Jeff, if you were to tell me what kind of errors you’re getting I may be able to help you. Even better would be if you were to visit #zftalk on freenode. Check http://www.zftalk.com
[...] [3] Naneau_View_Smarty [...]
Worked peferctly. I never worked with MVC or smarty before, and I like it.
Now I am trying to get it work with modules:
In the bootstrap:
$controller->setControllerDirectory(array(
‘default’ => $dir,
‘produkte’ => $dir.’/section’
))
If I go to url/section it says:
Warning: Smarty error: unable to read resource: “” in ……………/application/library/Smarty/Smarty.class.php on line 1095
Any Idea?
I would like to advise you to have a look at the module directory convention for the framework. I think what goes wrong is that you have a “weird” directory layout, the viewRenderer doesn’t understand. It tries to render a view script that obviously doesn’t exist.
Have a look at:
http://naneau.nl/2007/06/03/on-modules/
Thanks for the quick replay.
Well, I found out the thing with the folder structure. It seems to work in various ways. But anytime the settings find the correct Controller it messes up at the point where I define the main-template in the postDispatch() with
Zend_Controller_Action::renderScript(‘index.tpl’);
it makes the smarty error.
Changing the index.tpl to something none existing produces the error:
exception ‘Zend_View_Exception’ with message ’script ‘indedx.tpl’ not found in path’
Maybe something with the baseUrl.
Strange beahvior:
in the bootstrap:
->setBaseUrl(‘/’)
If I set this to somethin (‘./notexisting’), you can call url/anything_that_has_exactly_as_much_letters) and you see the startpage.
This is a bit too complex to solve from the top of my head right now. I’d be happy to help you on IRC though. #zftalk on freenode. See http://www.zftalk.com for more details and a java applet that will get you online
Hey,
I’m new to the Zend Framework but I used Smarty for previous projects. I implemented it the way you suggested and everything worked fine. Then I tried the view helpers but they did not work correctly when I use an array for the attributes.
The source in the template looks like this:
….
{$this->formText(‘firstName’,$this->user->firstName,array),array(‘class’=>’test’)}
…
It produceses the following error:
Fatal error: Smarty error: [in user/_form.phtml line 6]: syntax error: unrecognized tag: $this->formText(‘firstName’,$this->user->firstName,array(‘class’=>’test’)) (Smarty_Compiler.class.php, line 446) in E:webdevelopmenthtdocsprojectsminislibraryzfSmartySmarty.class.php on line 1095
In your first article on this topic, you mentioned, that they could be used doing the stuff your way.
Thanks.
You are right, I should have mentioned that using arrays can be a pit of a pain. As far as I know there isn’t a way to do this natively in smarty, as all it’s functions/plugins have a different way of passing parameters. The only way to call view helpers that need an associative array of parameters is:
{php}
echo $this->get_template_vars(‘this’)->formSubmit(’s’, ‘Get list’, array(‘class’ => ’submit’));
{/php}
Fortunately, you shouldn’t need them too often.
When working with modules there seems to be a problem with the compileDir. Say you have two modules and in both an index/index.tpl template. Then only the first called is compiled. For the call to the second module the allready compiled and now wrong code is used.
Solved it by adding a cacheID/compileID based an actual scriptPaths to your class:
$cacheID = md5($file.serialize($this->getScriptPaths()));
echo $this->_smarty->fetch($file, $cacheID, $cacheID);
Cheers, Sven.
you are absolutely right. In fact, I had already done something similar myself. I will release a new version with some small fixes, as well as _very_ rigorous installation instructions soon. Thank you for your input.
Just wrote a little Smarty-Plugin to get Helpers working and wanted to share it… Perhaps anybody knows a better way to do it…
function.helper.php:
_tpl_vars['this'], $params['helper']), $param1, $param2, $param3, $param4);
}
and in your template something like this:
{helper helper=”url” param1=’array(“module” => “index”, “controller” => “login”)’}
{helper helper=”formText” param1=’firstName’ param2=’testing’ param3=’array(“class”=>”test”)’}
Perhaps this could be better solved overwriting the default __call() implementation?
function.helper.php:
function smarty_function_helper($params, &$smarty)
{
$c = 1;
while (isset($params['param'.$c])) {
eval(‘$param’.$c.’ = ‘.$params['param'.$c].’;');
$c++;
}
return call_user_func(array($smarty->_tpl_vars['this'], $params['helper']), $param1, $param2, $param3, $param4);
}
Again you beat me to something I was going to write about. While I don’t think this solution is the most elegant way of doing this, I do agree that there should be a way of calling the view helpers in a more “smarty” like fashion (not relying on {$this->helperName()}.
Will have a look at it tomorrow!
Thanks.
I optimized the helper-function a little. Now the number of parameters is unlimited. But I’m not happy with the naming (param1, param2). Only arrays get eval’ed.
function smarty_function_helper($params, &$smarty)
{
$c = 1;
while (isset($params['param'.$c])) {
if (preg_match(‘/^array(/’, $params['param'.$c])) {
eval(‘$param[] = ‘.$params['param'.$c].’;');
} else {
$param[] = $params['param'.$c];
}
$c++;
}
return call_user_func_array(array($smarty->_tpl_vars['this'], $params['helper']), $param);
}
Nice… I actually posted something slightly similar to your view class to my blog just yesterday, not having googled properly… =)
What comes to that helper plugin, I’d rather use strpos instead of preg_match as it’s probably faster… can’t say for sure since it’s not a very complex match. Nice use of eval() though, I would probably just have used explode() and a different syntax for the parameters.
the template dir assignment doesn’t work for me. As soon as I include another template (e.g. {include file=’header.tpl’}) this resource isn’t found. I’d suggest changing the template directory code like this:
2
3
$file = $path_parts['basename'];
$this->_smarty->template_dir = $path_parts['dirname'];
Hi naneau, are you fixed the problem about e-sven said?
Jean-Claude: I would suggest using E-sven’s smarty function. It’s the best way of getting around the problem without using {php}-blocks.
Cydo, yes, file inclusion doesn’t work like you would expect. The template_path is set to the scripts directory you use for your views. Your patch does solve that problem (and restores it to “default” smarty behaviour).
I worked around that with another dirty, but working, solution:
public function _array()
{
eval (‘$array = array(‘ . func_get_arg(0) . ‘);’);
return $array;
}
{$this->url($this->_array(“‘controller’ => ‘test’, ‘action’ => ‘test’”), ‘routeName’)}
Comes in handy whenever an on-the-fly array is needed, is readable and just a very small extension to the Zend_View Smarty connector class and through returning can also be wrapped in other functions. Feedback on my approach welcome
I can not get it to work, and yes i know it is my own limitation and lack of solid php knowledge.
But … can you provide a simple skeleton application that can serve as template/example to get me (and maybe other started).
I struggle with the controller and view (smarty) to work together.
you would make me very happy,
thanks
[...] also an another good Zend Smarty implementation at Naneau’s blog. The implementation differs slightly from mine, but I don’t really know which one is [...]
[...] (参考 http://naneau.nl/2007/05/31/using-naneau_view_smarty-with-rc1/ [...]
I keep getting an empty/blank page.
My bootstrap looks like:
setView( new Naneau_View_Smarty( array( ‘compileDir’ => $applicationConfigs->get( ’smarty.compile_dir’ ) ) ) );
$viewRenderer->setViewSuffix( ‘tpl’ );
Zend_Controller_Action_HelperBroker::addHelper( $viewRenderer );
$frontController = Zend_Controller_Front::getInstance();
$frontController->registerPlugin( new Zend_Controller_Plugin_ErrorHandler() );
$frontController->setControllerDirectory( array( ‘default’ => Zend_Registry::get( ‘appConfigs’ )->application->path . ‘controllers’ ) );
$frontController->throwExceptions( true );
$frontController->setParam( ‘noViewRenderer’, true );
$frontController->dispatch();
?>
index.phtml and index.tpl both reside in /application/views/scripts/index
The IndexController has an empty method ‘indexAction()’.
What am I doing wrong?
Found my mistake – I accessed the Zend_Config in a wrong way. Smarty templates are now loaded.
Hi Naneau,
Your blog is great.
Recently I bumped into the following problem:
I am using a conventional modular directory layout.
When I access
http://…../myapp/mymodule/index/index
I keep getting the result (view output) of
http://…../myapp/default/index/index
So, after a lot of digging, I found that when I’m using
the same compile_dir for all the templates, I should use
a different $compile_id when fetching for templates
that have the same filename. (my case: index.tpl)
I included here a snippet of code thast illustrates the
modification made to your class.
Naneau_View_Smarty.php
[...]
$this->_smarty->template_dir = $path[0];
//set the template diretory as the first directory from the path
/**
* fetch the template assigning a compile_id, so it can distinguish
* between the same filenames but different template_paths
*
* @author Marinel Marian
*/
echo $this->_smarty->fetch($file, null, $path[0]);
//process the template (and filter the output)
[...]
Just thought to post this in case anybody has the same problem.
Keep up the good work.
[...] Integración de Smarty y Zend_Framework I (incluye la clase para integrar) Integración de Smarty y Zend_Framework II [...]
Hi Naneau,
Congratulations for your work!
I have a question …
I’m using Naneau_View_Smarty and must also use the Zend_Layout …
But not been successful..
Here is the code:
In layout.phtml: (this is the layout that I call in bootstrap with the Zend_layout)
{$this->render(‘top.phtml’)}
{$this->render(‘left.phtml’)}
{$this->layout()->content}
{$this->render(‘footer.phtml’)}
The render with top, left, and footer pages that’s all ok! But the content don’t work as well..
The error:
Fatal error: Smarty error: [in layout.phtml line 21]: syntax error: unrecognized tag: $this->layout()->content (Smarty_Compiler.class.php, line 446) in C:xampphtdocscria_projetositelibSmartySmarty.class.php on line 1091
how can I solve this?
Have I another way to render the view page (for example: index.phtml) in the div “content”?
Your blog is great!
Thanks..
Hi,
I was wondering if there is a final (newer) version of the class with the same-name-problem solved (see post from Marineau – January 12, 2008)
Hi,
it’s a great post.
i have a question: if i have two modules, say ‘default’ and ‘foo’, both module use some common view scripts, ie, footer.tpl, header.tpl, etc. so how can i make view scripts in both module include these common files, use smarty include. thanks.
one solution i may use was put view scripts of all modules in a dir, and change,and use setViewBasePathSpec(), setViewScriptPathSpec() change its default behaviors. so is there any better solutions?
[...] the article here: Naneau " Using Naneau_View_Smarty with RC1 Share and [...]
Hi,
thanks for this fantastic class. I use it with the new 1.9.1 version and it works very fine.
Ok and now a virsion to work with ZF 1.10???
Many tuts i find abouth smarty and ZF are very old!
France4U managers in mooie Franse regio’s helpen zelf met uw droom huis vinden en kopen. Online updates. Uw Huis in Frankrijk via France 4U.