Giter VIP home page Giter VIP logo

Comments (15)

oherych avatar oherych commented on May 30, 2024

Smarty like main or additional ViewRenderer?

from yii2.

samdark avatar samdark commented on May 30, 2024

Additional.

from yii2.

oherych avatar oherych commented on May 30, 2024

fooh, you reassured me

from yii2.

sensorario avatar sensorario commented on May 30, 2024

We could use each renderer we want?

from yii2.

samdark avatar samdark commented on May 30, 2024

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

from yii2.

cebe avatar cebe commented on May 30, 2024

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

Why not choose renderer by file extension?

from yii2.

rawtaz avatar rawtaz commented on May 30, 2024

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.

from yii2.

samdark avatar samdark commented on May 30, 2024

@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'));
}

from yii2.

rawtaz avatar rawtaz commented on May 30, 2024

@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.

from yii2.

samdark avatar samdark commented on May 30, 2024

@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.

from yii2.

rawtaz avatar rawtaz commented on May 30, 2024

@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.

from yii2.

cebe avatar cebe commented on May 30, 2024

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

from yii2.

samdark avatar samdark commented on May 30, 2024

Will check what I can do with it...

from yii2.

qiangxue avatar qiangxue commented on May 30, 2024

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.

from yii2.

samdark avatar samdark commented on May 30, 2024

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',
        ),
    ),
),

from yii2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.