Skip to content

Twig_Environment::loadTemplate should not accept just "names" #6

Description

@ravishi

I have a loader that loads objects. If the object implements a Project_ResourceInterface, that provides a method getSource(), then the loader can handle this object and return the source.

It works very, very well. I can have the following sintax in my templates:

{{ include page.part.body }} -- or something similar

The only problem is this line at Twig_Environment class:

return $this->loadedTemplates[$name] = new $cls($this);

If $name is a object, I get a PHP Illegal offset type error. I've changed that to:

return $this->loadedTemplates[(string) $name] = new $cls($this);

and each of my resources have a __toString method that returns a unique identifier.

I think you could make that a bit more flexibe if those loadedTemplates was generated in a more flexibe way, maybe calling a method from the loader.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions