Re: [SMARTY] Including modules

From: Date: Fri, 15 Apr 2005 21:35:28 +0000
Subject: Re: [SMARTY] Including modules
References: 1 2 3 4 5 6  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12517@lists.php.net to get a copy of this message
My only thing is that I wanted to keep SQL and etc. out of the smarty function. My plan was to only use smarty functions for things that are portable, i.e. rss feeds, weather, stock ticker, etc... Perhaps I can take a look Smarty.class.php and see if I can tweak it to fit stubborn ways? *shrug* > This approach has worked for me... > > header.tpl: > > {load_top_nav assign="nav_data"} > {* navigation display goes here, example: *} > {foreach from=$nav_data key="key" item="val"} > {html_options values=$key output=$val} > {/foreach} > > > plugins/function.load_top_nav.php: > > function smarty_function_load_top_nav($params,&$smarty) { > // do SQL, etc. to load up the navigation data array (with NO > presentation markup!) > return $nav_data; > } > > > > Now you have your application code in a separate function, and your > presentation 100% in smarty templates. There is no recursive smarty > template fetches or similar complications involved. > > > Jonathan Villa wrote: > >>I figured that... *shrug* >> >>Here's what I've done >> >>on header.tpl >>{top_nav} >> >>then in plugins/function.top_nav.php >> >>function smarty_function_top_nav($params, &$smarty) >>{ >> include('top_nav.php'); >>} >> >>then on top_nav.php >> >>$smarty->display('top_nav.tpl'); >>and tried >>$this->display('top_nav.tpl'); >> >>errors are >> >>smarty: Fatal error: Call to a member function display() on a non-object... >>this: Fatal error: Using $this when not in object context in... >> >>you're probably wondering, why don't I just put my logic in the >>smarty_function_top_nav function like it's supposed to be... >> >>well answer is because I want application specific code in the same >> directory...I'll >>only be giving write permissions to a specific directory to future developers... so >>I don't want them worry about Smarty... just pretty much running middle tier >> code... >> >>*shrug* >> >> >> >> >>>FYI, when you are inside of something like {php_include}, the proper >>>object name is $this->func(), not $smarty->func(). >>> >>>Jonathan Villa wrote: >>> >>> >>> >>>>>why not refactor these 3 as smarty plugins... >>>>>then you can do stuff like: >>>>> >>>>>header.tpl >>>>>----------- >>>>>{top_nav} >>>>>{left_nav} >>>>>{right_nav} >>>>> >>>>> >>>>>take a look at the files in the plugins dir of smarty for info >>>>>on how to write a smarty function/plugin. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>I did exactly that but I kept getting an error about $smarty-> not being >>>>instantiated... you know the error "xxxon a non object" >>>> >>>>I'm instantiating it in file called app-config.inc that get's prepended to >>>>all >>>>application files... that setup has worked for months... just get an error when >>>>trying to use it in a smarty plugin. >>>> >>>> >>>> >>>> >>>> >>> >>> >> >> >> > >

« previous php.smarty.general (#12517) next »