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

Implement SmartyViewRenderer #29

Closed
qiangxue opened this issue Mar 25, 2013 · 15 comments
Closed

Implement SmartyViewRenderer #29

qiangxue opened this issue Mar 25, 2013 · 15 comments
Assignees
Labels
status:under development Someone is working on a pull request. type:feature
Milestone

Comments

@qiangxue
Copy link
Member

No description provided.

@ghost ghost assigned samdark Mar 25, 2013
@oherych
Copy link

oherych commented Mar 25, 2013

Smarty like main or additional ViewRenderer?

@samdark
Copy link
Member

samdark commented Mar 25, 2013

Additional.

@oherych
Copy link

oherych commented Mar 25, 2013

fooh, you reassured me

@sensorario
Copy link
Contributor

We could use each renderer we want?

@samdark
Copy link
Member

samdark commented Mar 25, 2013

Yes. One at a time with fallback to plain PHP.

@cebe
Copy link
Member

cebe commented Mar 26, 2013

Yes. One at a time with fallback to plain PHP.

Why not choose renderer by file extension?

@rawtaz
Copy link
Contributor

rawtaz commented Mar 26, 2013

Just a note on choosing renderer by file extension; I've seen people needing to use a specific renderer even though the file extensions of their view files didn't match that renderer. I wouldn't think it's a good idea to lock it down to file suffix.

@samdark
Copy link
Member

samdark commented Mar 26, 2013

@rawtaz it's not using suffixes like in 1.1 anymore. In the controller you have to specify it explicitly:

public function actionSmarty()
{
    echo $this->render('renderer.tpl', array('username' => 'Alex'));
}

@rawtaz
Copy link
Contributor

rawtaz commented Mar 26, 2013

@samdark Thank you for pointing that out. I think the thing I mentioned might still apply though, if the/which renderer to use would be decided by looking at the file suffix in the first argument to render.

@samdark
Copy link
Member

samdark commented Mar 26, 2013

@rawtaz nope. Renderer is an application component. There's no sense in using both Smarty and Twig in a single application so user will be able to configure one renderer at a time.

@rawtaz
Copy link
Contributor

rawtaz commented Mar 26, 2013

@samdark All I can say is that this was not the case for the user I was thinking about. I don't remember the specifics (can probably look it up if needed).

Regardless, why would there not possibly be circumstances where one needs to render views of different types? You could have for example a system that renderPartial()s some views from other systems, e.g. the system itself uses regular PHP views but it needs to renderPartial() Smarty or Twig views provided by some other party.

EDIT: And in relation to that, there might be cases where the view file to render doesn't have a file suffix that precisely matches the renderer's default.

@cebe
Copy link
Member

cebe commented Mar 26, 2013

Maybe there could be a paramater like cacheId to specify the application component to be used as the renderer

@samdark
Copy link
Member

samdark commented Mar 26, 2013

Will check what I can do with it...

@qiangxue
Copy link
Member Author

Renderer is no longer an application component, but a property of the "view" application component.

For needs like using multiple renderers simultaneously, you can create a wrapper renderer. Within this renderer you can write whatever logic in determining which render to use. We may consider providing such a wrapper renderer in the core which by default chooses view renderer by view file extension.

@samdark
Copy link
Member

samdark commented Apr 3, 2013

Basic implementation done. Also implemented CompositeViewRenderer that allows using multiple renderers at once with the following config:

'components' => array(
    'view' => array(
        'class' => 'yii\base\View',
        'renderer' => array(
            'class' => 'yii\renderers\CompositeViewRenderer',
            'renderers' => array(
                'tpl' => array(
                    'class' => 'yii\renderers\SmartyViewRenderer',
                ),
                'twig' => array(
                    'class' => 'yii\renderers\TwigViewRenderer',
                ),
            ),

            // that's how to use only one renderer
            //'class' => 'yii\renderers\TwigViewRenderer',
        ),
    ),
),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:under development Someone is working on a pull request. type:feature
Projects
None yet
Development

No branches or pull requests

6 participants