Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples of usage #3

Closed
electricowl opened this issue Oct 18, 2012 · 4 comments
Closed

Examples of usage #3

electricowl opened this issue Oct 18, 2012 · 4 comments

Comments

@electricowl
Copy link

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
Copy link
Author

I found it...

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

@maxnuf
Copy link
Owner

maxnuf commented Oct 18, 2012

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
Copy link
Owner

maxnuf commented Oct 18, 2012

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants