ViewRenderer and Smarty

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

ViewRenderer and Smarty

Ralf Eggert
Hi,

I finally found some time to read into the ViewRenderer docs and I
really like what I read. I just have one questions before I start to use
ViewRenderer in my project. I am using Smarty as my template engine and
have implemented the Zend_View_Interface as suggested in the manual:

http://framework.zend.com/manual/en/zend.view.scripts.html#zend.view.scripts.templates

When I want to use the ViewRenderer with my Zend_View implementation for
Smarty, is there anything I should keep in mind that might work a little
different with the ViewRenderer than described in the manual here:

http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.viewrenderer

Maybe some one has stumbled on any issues yet and could give some advice?

Thanks and Best Regards,

Ralf
Reply | Threaded
Open this post in threaded view
|

Re: ViewRenderer and Smarty

Ralf Eggert
Hi again,

just another question. At the moment I am using a site wide template
which holds all the basic layout and stuff. Very much simplified it
looks like this:

  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
  <head>
  <title>{$page.title|default:"Start"} - travello.com</title>
  </head>
  <body>
  <div id="nav">
  ...
  </div>
  <div id="main">
  <h1>{$page.title|default:"Start"}</h1>
  {include file=$page.template_file}
  </div>
  </body>

The Smarty variable $page holds (besides some other values) the name of
the template which needs to be rendered for the current module,
controller and action. So I already solved the problem of matching
module, controller and actions to the specific template myself.

Since ViewRenderer tries to identify the template to be rendered  by
itself I won't really need this, will I? Should I use setNeverRender()
or should I rather extend Zend_Controller_Action_Helper_ViewRenderer to
implement my own rendering logic by setting my $page Smarty variable?

Thanks for your advice!

Best Regards,

Ralf

Reply | Threaded
Open this post in threaded view
|

Re: ViewRenderer and Smarty

Kevin McArthur-2
Ralf,

Work is ongoing on Zend_Layout, should ahve something presentable in a few
days.

Its designed to make this approach (officially called two-step-view) a lot
easier.

K
----- Original Message -----
From: "Ralf Eggert" <[hidden email]>
To: "Zend Framework MVC" <[hidden email]>
Sent: Saturday, June 02, 2007 9:45 AM
Subject: Re: [fw-mvc] ViewRenderer and Smarty


> Hi again,
>
> just another question. At the moment I am using a site wide template
> which holds all the basic layout and stuff. Very much simplified it
> looks like this:
>
>  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
>  <head>
>  <title>{$page.title|default:"Start"} - travello.com</title>
>  </head>
>  <body>
>  <div id="nav">
>  ...
>  </div>
>  <div id="main">
>  <h1>{$page.title|default:"Start"}</h1>
>  {include file=$page.template_file}
>  </div>
>  </body>
>
> The Smarty variable $page holds (besides some other values) the name of
> the template which needs to be rendered for the current module,
> controller and action. So I already solved the problem of matching
> module, controller and actions to the specific template myself.
>
> Since ViewRenderer tries to identify the template to be rendered  by
> itself I won't really need this, will I? Should I use setNeverRender()
> or should I rather extend Zend_Controller_Action_Helper_ViewRenderer to
> implement my own rendering logic by setting my $page Smarty variable?
>
> Thanks for your advice!
>
> Best Regards,
>
> Ralf
>

Reply | Threaded
Open this post in threaded view
|

Re: ViewRenderer and Smarty

alesl
In reply to this post by Ralf Eggert
Hi!

If you want to use Smarty with ZF try this aproach:
http://naneau.nl/2007/05/31/using-naneau_view_smarty-with-rc1

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() …

In my bootstrap file i've add:
$viewRenderer->setViewScriptPathSpec(’:module/:controller/:action.:suffix’);
so it’s very easy to include other templates …

index.tpl:
<body>
{include file=’default/index/header.tpl’}
<div id="content">
    Lorem Ipsum
</div>
{include file=’default/index/footer.tpl’}
</body>

Regards,
AlesL


Ralf Eggert wrote:
Hi,

I finally found some time to read into the ViewRenderer docs and I
really like what I read. I just have one questions before I start to use
ViewRenderer in my project. I am using Smarty as my template engine and
have implemented the Zend_View_Interface as suggested in the manual:

http://framework.zend.com/manual/en/zend.view.scripts.html#zend.view.scripts.templates

When I want to use the ViewRenderer with my Zend_View implementation for
Smarty, is there anything I should keep in mind that might work a little
different with the ViewRenderer than described in the manual here:

http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.viewrenderer

Maybe some one has stumbled on any issues yet and could give some advice?

Thanks and Best Regards,

Ralf
  
Reply | Threaded
Open this post in threaded view
|

Re: ViewRenderer and Smarty

Ralf Eggert
In reply to this post by Kevin McArthur-2
Hi Kevin,

> Work is ongoing on Zend_Layout, should ahve something presentable in a few
> days.
>
> Its designed to make this approach (officially called two-step-view) a lot
> easier.

Thanks for your note. Ok, I will wait for Zend_Layout. Just one question
ahead since I did not look into Zend_Layout yet. Will Zend_Layout
support Smarty then as well or is Zend_Layout easily extensible to work
together with Smarty?

But hopefully some one has an answer for my introductive questions as
well regarding ViewRenderer...

Thanks and Best Regards,

Ralf

Reply | Threaded
Open this post in threaded view
|

Re: ViewRenderer and Smarty

Ralph Schindler
Ralf Eggert wrote:

> Hi Kevin,
>
>> Work is ongoing on Zend_Layout, should ahve something presentable in a few
>> days.
>>
>> Its designed to make this approach (officially called two-step-view) a lot
>> easier.
>
> Thanks for your note. Ok, I will wait for Zend_Layout. Just one question
> ahead since I did not look into Zend_Layout yet. Will Zend_Layout
> support Smarty then as well or is Zend_Layout easily extensible to work
> together with Smarty?

Yep, basically, its View Object independent, what ever View Object you
use in your action controllers is the same view object you will use at
the layout layer... this also means they can share view variables.

-ralph

Reply | Threaded
Open this post in threaded view
|

Re: ViewRenderer and Smarty

Ralf Eggert
In reply to this post by alesl
Hi Ales,

thanks for your reply.

> index.tpl:
> <body>
> {include file=’default/index/header.tpl’}
> <div id="content">
>     Lorem Ipsum
> </div>
> {include file=’default/index/footer.tpl’}
> </body>

So, if I understand this correctly, this approach would mean that I need
to add the inclusion of my header and footer template to all of my
templates. At the moment I rather prefer my solution if it is possible
to use it with the ViewRenderer without any big hassle.

Thanks anyway and Best Regards,

Ralf
Reply | Threaded
Open this post in threaded view
|

Re: ViewRenderer and Smarty

Ralf Eggert
In reply to this post by Ralph Schindler
Hi Ralph,

> Yep, basically, its View Object independent, what ever View Object you
> use in your action controllers is the same view object you will use at
> the layout layer... this also means they can share view variables.

Ok, thanks for clarification. So I will wait and see if Zend_Layout will
help me to solve this issue.

Best Regards,

Ralf

Reply | Threaded
Open this post in threaded view
|

Re: ViewRenderer and Smarty

Kevin McArthur-2
In reply to this post by Ralf Eggert
This is _exactly_ the type of use Layout is designed to discourage. See
the -general debate.

Patience, your original approach is correct. Wait for layout.

K
----- Original Message -----
From: "Ralf Eggert" <[hidden email]>
To: "Zend Framework MVC" <[hidden email]>
Sent: Saturday, June 02, 2007 2:04 PM
Subject: Re: [fw-mvc] ViewRenderer and Smarty


> Hi Ales,
>
> thanks for your reply.
>
>> index.tpl:
>> <body>
>> {include file=’default/index/header.tpl’}
>> <div id="content">
>>     Lorem Ipsum
>> </div>
>> {include file=’default/index/footer.tpl’}
>> </body>
>
> So, if I understand this correctly, this approach would mean that I need
> to add the inclusion of my header and footer template to all of my
> templates. At the moment I rather prefer my solution if it is possible
> to use it with the ViewRenderer without any big hassle.
>
> Thanks anyway and Best Regards,
>
> Ralf

Reply | Threaded
Open this post in threaded view
|

Re: ViewRenderer and Smarty

Ralf Eggert
Hi Kevin,

> Patience, your original approach is correct. Wait for layout.

That is exactly what I will be doing now after examining ViewRenderer.
Set "noViewRenderer" to true and keep on working. There is still enough
to do... :-)

Best Regards,

Ralf


Reply | Threaded
Open this post in threaded view
|

Re: ViewRenderer and Smarty

akrabat
In reply to this post by Ralf Eggert
Ralf Eggert wrote:

> Since ViewRenderer tries to identify the template to be rendered  by
> itself I won't really need this, will I? Should I use setNeverRender()
> or should I rather extend Zend_Controller_Action_Helper_ViewRenderer to
> implement my own rendering logic by setting my $page Smarty variable?

I extended Zend_Controller_Action_Helper_ViewRenderer. My notes on what
I did are at
http://akrabat.com/2007/06/02/extending-viewrenderer-to-support-layout-templates/

Zend_Layout promises to be much more feature packed though!

Regards,

Rob...
Reply | Threaded
Open this post in threaded view
|

Re: ViewRenderer and Smarty

alesl
In reply to this post by Kevin McArthur-2
Well some prefer to have common header and footer templates in every
singe view file , others use standard site-view layout file that
displays the content of the action script files.

Let's assume you have 5 modules (default, employer, jobseeker, forum ,
...) and in every one of them about 10 site-view templates (different
colors, 2-3 column layouts for user to choose, ...)  You have to add in
HTML head section some javascript code and css styles and right before
</body> tag Javascript tracking code.
In first aproach you'll have to edit just 2 files -
'default/index/header.tpl' and 'default/index/footer.tpl' (maybe some
other). In second approach there are about 50 files to edit ...

Best solution is in my opinion to combine this two approaches and have
"ultimate" Zend_Layout!

AlesL


Kevin McArthur wrote:

> This is _exactly_ the type of use Layout is designed to discourage.
> See the -general debate.
>
> Patience, your original approach is correct. Wait for layout.
>
> K
> ----- Original Message ----- From: "Ralf Eggert" <[hidden email]>
> To: "Zend Framework MVC" <[hidden email]>
> Sent: Saturday, June 02, 2007 2:04 PM
> Subject: Re: [fw-mvc] ViewRenderer and Smarty
>
>
>> Hi Ales,
>>
>> thanks for your reply.
>>
>>> index.tpl:
>>> <body>
>>> {include file=’default/index/header.tpl’}
>>> <div id="content">
>>>     Lorem Ipsum
>>> </div>
>>> {include file=’default/index/footer.tpl’}
>>> </body>
>>
>> So, if I understand this correctly, this approach would mean that I need
>> to add the inclusion of my header and footer template to all of my
>> templates. At the moment I rather prefer my solution if it is possible
>> to use it with the ViewRenderer without any big hassle.
>>
>> Thanks anyway and Best Regards,
>>
>> Ralf
>