Wanze Posted July 3, 2014 Share Posted July 3, 2014 TemplateEngineSmarty This module adds Smarty as engine to the TemplateEngineFactory. Screenshot of the available configuration options: Project on GitHub: https://github.com/wanze/TemplateEngineSmarty Project in modules directory: http://modules.processwire.com/modules/template-engine-smarty/ Only Smarty related things should be discussed in this thread. For common problems/features/questions about the Factory, use the TemplateEngineFactory thread. Edit: I added a section to the readme on GitHub how I think Smarty works best in combination with the TemplateEngineFactory and ProcessWire. I used this technique in a recent project and I'm very happy with it. 4 Link to comment Share on other sites More sharing options...
centaur78 Posted April 7, 2016 Share Posted April 7, 2016 Hi wanze, I am trying to use the MenuBuilder module for the past one week along with smarty template.. The below is used in header.tpl (smarty template) <nav class="menu"> {$menu = $modules->get("MarkupMenuBuilder")} {$menu->render('testmenu')} </nav> I am able to generate the menu but without being able provide css class for the submenus, however as soon i add $options as mentioned in MenuBuilder docs like below <nav class="menu"> {$options = array( 'wrapper_list_type' => 'ul', 'list_type' => 'li', 'menu_css_class' => 'type-1', 'submenu_css_class' => 'dropmenu', 'current_class' => 'active', 'default_title' => 0, 'include_children' => 4, 'm_max_level' => 1, 'current_class_level' => 1, )} {$menu = $modules->get("MarkupMenuBuilder")} {$menu->render('testmenu', $options)} </nav> i get this error Notice: Trying to get property of non-object in D:\xampp\htdocs\pw\site\modules\TemplateEngineSmarty\TemplateEngineSmarty.module on line 145 Fatal error: Exception: Syntax error in template "D:\xampp\htdocs\pw\site\templates\views\partials\header.tpl" on line 16 "'wrapper_list_type' => 'ul'," - Unexpected " => ", expected one of: "","" , ")" (in D:\xampp\htdocs\pw\site\modules\TemplateEngineSmarty\TemplateEngineSmarty.module line 109) #0 D:\xampp\htdocs\pw\site\modules\TemplateEngineFactory\TemplateEngineFactory.module(100): TemplateEngineSmarty->render() #1 D:\xampp\htdocs\pw\wire\core\Wire.php(459): TemplateEngineFactory->hookRender(Object(HookEvent)) #2 D:\xampp\htdocs\pw\wire\core\Wire.php(333): Wire->runHooks('render', Array) #3 D:\xampp\htdocs\pw\wire\modules\Process\ProcessPageView.module(187): Wire->__call('render', Array) #4 D:\xampp\htdocs\pw\wire\modules\Process\ProcessPageView.module(187): Page->render() #5 [internal function]: ProcessPageView->___execute(true) #6 D:\xampp\htdocs\pw\wire\core\Wire.php(398): call_user_func_array(Array, Array) #7 D:\xampp\htdocs\pw\wire\core\Wire.php(333): Wire->runHooks('execute', Array) #8 D:\xampp\htdocs\pw\ind in D:\xampp\htdocs\pw\index.php on line 248 Error: Exception: Syntax error in template "D:\xampp\htdocs\pw\site\templates\views\partials\header.tpl" on line 16 "'wrapper_list_type' => 'ul'," - Unexpected " => ", expected one of: "","" , ")" (in D:\xampp\htdocs\pw\site\modules\TemplateEngineSmarty\TemplateEngineSmarty.module line 109) #0 D:\xampp\htdocs\pw\site\modules\TemplateEngineFactory\TemplateEngineFactory.module(100): TemplateEngineSmarty->render() #1 D:\xampp\htdocs\pw\wire\core\Wire.php(459): TemplateEngineFactory->hookRender(Object(HookEvent)) #2 D:\xampp\htdocs\pw\wire\core\Wire.php(333): Wire->runHooks('render', Array) #3 D:\xampp\htdocs\pw\wire\modules\Process\ProcessPageView.module(187): Wire->__call('render', Array) #4 D:\xampp\htdocs\pw\wire\modules\Process\ProcessPageView.module(187): Page->render() #5 [internal function]: ProcessPageView->___execute(true) #6 D:\xampp\htdocs\pw\wire\core\Wire.php(398): call_user_func_array(Array, Array) #7 D:\xampp\htdocs\pw\wire\core\Wire.php(333): Wire->runHooks('execute', Array) #8 D:\xampp\htdocs\pw\ind This error message was shown because site is in debug mode ($config->debug = true; in /site/config.php). Error has been logged. I am not sure what i am doing wrong here ?? The errors seems to be about how i am calling the options using the smarty tags Link to comment Share on other sites More sharing options...
Wanze Posted April 7, 2016 Author Share Posted April 7, 2016 Hi cenatur78, Try to do the logic of building your menu in the "controller", not in the smarty template. Then you can pass the markup to the smarty template, e.g. $view->menu = $menu->render('testmenu'); Cheers Link to comment Share on other sites More sharing options...
qtguru Posted May 28, 2016 Share Posted May 28, 2016 I think there's a limitation in this module: Let's imagine this scenario I have a page with fetches images and i need to do a thumbnail resize for each image however I do not know how to register a function with this module as in Smarty i can handle that but i don't have access to the current Smarty context, so right now I'm stuck, if there's a way i can my defined PHP functions in the smarty template, i'd appreciate it. Thanks UPDATE: It seems this works but we might need to expose some features to allow registering of functions, mind if i fork and send a PR ? class HomeController{ public function getTitle($page){ return $page->title; } } $home =new HomeController(); $view->set("title",$title); $view->set("content",$page->body); $view->set("images",$page->sliderImages); $view->set("controller",$home); Link to comment Share on other sites More sharing options...
Wanze Posted May 29, 2016 Author Share Posted May 29, 2016 You can hook after this method to further customize Smarty: https://github.com/wanze/TemplateEngineSmarty/blob/master/TemplateEngineSmarty.module#L130 Just ask if you need examples Cheers Link to comment Share on other sites More sharing options...
qtguru Posted May 29, 2016 Share Posted May 29, 2016 Thanks i think this is the best module ever, I can't build any Processwire anymore unless i use this Smarty module, always had issues with traditional Processwire templating but this is dynamic, thanks for the response my eyes didn't catch that method. 1 Link to comment Share on other sites More sharing options...
tpr Posted May 29, 2016 Share Posted May 29, 2016 Haha, same feelings here with another template engine. Once you get the hang of it there's no way back 1 Link to comment Share on other sites More sharing options...
qtguru Posted May 29, 2016 Share Posted May 29, 2016 I used the Smarty template module to build a site the flexibility and block system reminds of MasterPages in ASP.NET Link to comment Share on other sites More sharing options...
qtguru Posted June 8, 2016 Share Posted June 8, 2016 any way to use Ajax in this smarty ? like stopping when it's ajax and just returning a JSON Link to comment Share on other sites More sharing options...
dotnetic Posted June 17, 2016 Share Posted June 17, 2016 any way to use Ajax in this smarty ? like stopping when it's ajax and just returning a JSON Take a look here https://processwire.com/talk/topic/6833-module-templateenginefactory/?p=78641 and also my comment https://processwire.com/talk/topic/6833-module-templateenginefactory/?p=122354 1 Link to comment Share on other sites More sharing options...
urz0r Posted September 29, 2016 Share Posted September 29, 2016 Hey, is there any way to support template inheritance programmatically? Right now, we are limited to calling {extends file='html.tpl'} in the first line of every template we want to inherit from html.tpl. However, this can also be done inside the smarty fetch call, see: http://www.smarty.net/docs/en/resources.extends.tpl Thanks for the awesome module though Link to comment Share on other sites More sharing options...
horst Posted September 29, 2016 Share Posted September 29, 2016 @Wanze, I ping you, as the above question seems to be for you. Link to comment Share on other sites More sharing options...
Wanze Posted October 14, 2016 Author Share Posted October 14, 2016 @urz0r Not at the moment, how would you use this function with the module, can you make an example? As for now, you can hook after TemplateEngineSmarty::initSmarty() and customize the Smarty object, but I guess that is not useful in this situation. Cheers Link to comment Share on other sites More sharing options...
qtguru Posted February 17, 2017 Share Posted February 17, 2017 Hi I noticed during development of Modules, if i attempt to use Process::setViewFile it calls the current TemplateFactoryEngine which in my case is the Smarty Engine and attempts to look for a view in the site, I want to create modules with external templates rather than having templates in the code. I want to ask if there's a current way to stop this action. I will research and find out but i won't mind pointers thanks. Link to comment Share on other sites More sharing options...
Wanze Posted February 19, 2017 Author Share Posted February 19, 2017 @Sephiroth Link to comment Share on other sites More sharing options...
Wanze Posted February 19, 2017 Author Share Posted February 19, 2017 I'm sorry for the empty post above; somehow I'm not able to write in the editor when editing And submitting the post was by mistake I don't understand your question, could you post some example code and explain in more detail what's the problem? The module should only attempt to render your page with smarty, if there exists a "myTemplate.tpl" smarty template to the corresponding "myTemplate.php" ProcessWire template. Link to comment Share on other sites More sharing options...
qtguru Posted February 20, 2017 Share Posted February 20, 2017 11 hours ago, Wanze said: I'm sorry I will delete the post above, somehow I'm not able to write when editing and the posting was by mistake I don't understand your question, could you post some example code and explain in more detail what's the problem? The module should only attempt to render your page with smarty, if there exists a "myTemplate.tpl" smarty template to the corresponding "myTemplate.php" ProcessWire template. This is so awkward, The issue was sorted out but i actually forgot to reply to this forum as i didn't get any notification. thanks 1 Link to comment Share on other sites More sharing options...
Manaus Posted August 7, 2017 Share Posted August 7, 2017 Hello, in the settings page I'd like to know what "Global Template File - Filename of a template file that is used as main template behind the API variable" is for. I tried to make up a layout.tpl and use the file name as field setting, but looks like {block} contents are not passed to the file. Thanks! Link to comment Share on other sites More sharing options...
Wanze Posted August 7, 2017 Author Share Posted August 7, 2017 6 hours ago, Manaus said: Hello, in the settings page I'd like to know what "Global Template File - Filename of a template file that is used as main template behind the API variable" is for. I tried to make up a layout.tpl and use the file name as field setting, but looks like {block} contents are not passed to the file. Thanks! This means that you will have the same smarty template behind the $view variable. Normally, each controller (ProcessWire template) has its own template, e.g. home.php --> home.tpl basic-page.php --> basic-page.tpl However, with smarty you do not need this feature. You can make use of template inheritance, so create a global "layout.tpl" and define your blocks. Then, in your child templates you can overwrite these blocks. Hope it helps! Cheers Link to comment Share on other sites More sharing options...
Manaus Posted August 8, 2017 Share Posted August 8, 2017 Thanks Wanze, still I noticed that if I use the Global File instead of the {extends} instruction, no block is being passed. Anyone tested this happening?... Link to comment Share on other sites More sharing options...
Wanze Posted August 8, 2017 Author Share Posted August 8, 2017 @Manaus Can you provide some example code? Unfortunately I do not understand what you mean by "no block is being passed". Is it possible you are mixing up features of the template engine with the module? In smarty, you use the {block} tags to define sections that are either inherited or overwritten in a child template. To overwrite a block, you must use {extends} in your child template. If you provide some code I'm sure I can help you Cheers 1 Link to comment Share on other sites More sharing options...
Manaus Posted August 8, 2017 Share Posted August 8, 2017 @wanze Global file should make {extends} useless if I understood right. That's because in child templates {extends} works also if no Global File is specified in the admin pane. I hope I clarified the issue... Link to comment Share on other sites More sharing options...
Wanze Posted August 9, 2017 Author Share Posted August 9, 2017 20 hours ago, Manaus said: @wanze Global file should make {extends} useless if I understood right. That's because in child templates {extends} works also if no Global File is specified in the admin pane. I hope I clarified the issue... No The global template file has nothing to do with smarty, it is a feature provided by the module that is available for all connected template engines. The global template file only means that you always get the same (smarty|twig|...)-template behind the $view API variable. As already said, you probably don't want to use a global template file with smarty, because you can use smartys template inheritance which is much more powerful. For me, this is the main reason to use a template engine. 1 Link to comment Share on other sites More sharing options...
Manaus Posted August 14, 2017 Share Posted August 14, 2017 Thanks Wanze, sorry I'm a bit dumb, what do you mean by "behind the $view API variable"? Link to comment Share on other sites More sharing options...
Wanze Posted August 16, 2017 Author Share Posted August 16, 2017 On 14.8.2017 at 5:50 PM, Manaus said: Thanks Wanze, sorry I'm a bit dumb, what do you mean by "behind the $view API variable"? I meant the active smarty template when you pass data in your controllers, e.g. $view->set('title', $page->title); The convention of the module is that the smarty template has the same name as the controller, e.g. home.tpl for your home.php file. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now