maxnuf / MaxnufSmarty

Zend Framework 2 Module that provides a Smarty rendering strategy
3 stars 3 forks source link

Examples of usage #3

Closed electricowl closed 12 years ago

electricowl commented 12 years ago

Hi,

Would you please provide an example or two of how MaxnufSmarty is used inside a Controller class.

How template variables are set for example and how the template is selected.

Many thanks.

Ian

electricowl commented 12 years ago

I found it...

public function indexAction() {
     $template = $this->serviceLocator->get('maxnufsmarty');
     $template->assign('animal', 'capybara');
     $template->assign('animal_name', 'Reginald');
}
maxnuf commented 12 years ago

I'll write some example template files soon.

MaxnufSmarty uses the same ViewModel as the PhpRenderer. So using it would be the same.

just return either an array or a ViewModel in your controller action.

for example:

$title = 'some title'
$message = 'some text'
return array('title' => $title, 'message' => $message);

The controller Foo\Controller\BazBatController, with action “doSomethingCrazy”, would be mapped to the template foo/baz-bat/do-something-crazy.

have a look at: http://framework.zend.com/manual/2.0/en/modules/zend.view.quick-start.html

maxnuf commented 12 years ago

Yes you could indeed directly assign your variables into smarty. But this would mean that you have to fetch the smarty instance from the servicelocator in every controller action.

Just return an array. The variables in your array will be automatically assigned to smarty.

electricowl commented 12 years ago

Thanks for your answers!

I've never used Smarty before and I'm getting to grips with ZF2 so thanks for the quick and helpful responses.

Yes you could indeed directly assign your variables into smarty. But this would mean that you have to fetch the smarty instance from the servicelocator in every controller action.

Just return an array. The variables in your array will be automatically assigned to smarty.

— Reply to this email directly or view it on GitHub.