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

TemplateFactory - variable template class (RFC) #141

Closed
f3l1x opened this issue Jun 7, 2016 · 7 comments
Closed

TemplateFactory - variable template class (RFC) #141

f3l1x opened this issue Jun 7, 2016 · 7 comments

Comments

@f3l1x
Copy link
Member

@f3l1x f3l1x commented Jun 7, 2016

Hi! I have and idea about TemplateFactory.

If you need to use your own Template class, you have to extend original TemplateFactory now.

What about this implementation?

protected $templateClass = 'Nette\Bridges\ApplicationLatte\Template';

public function createTemplate(UI\Control $control = NULL)
{
    $latte = $this->latteFactory->create();
    $template = new $this->templateClass($latte);
    $presenter = $control ? $control->getPresenter(FALSE) : NULL;
    //...
}

public function setTemplateClass($class) 
{
    $this->templateClass = $class;
}

What do you think? It makes TemplateFactory more flexible. You can setup your template implementation over NEON config.

services:
    latte.templateFactory:
        setup:
            - setTemplateClass(My\Custom\Template)

Thanks for feedback.

@TomasVotruba

This comment has been minimized.

Copy link

@TomasVotruba TomasVotruba commented Sep 22, 2016

What is the use case for this?

@mrtnzlml

This comment has been minimized.

Copy link
Contributor

@mrtnzlml mrtnzlml commented Sep 23, 2016

@TomasVotruba For example this.

@TomasVotruba

This comment has been minimized.

Copy link

@TomasVotruba TomasVotruba commented Sep 24, 2016

@mrtnzlml I see.

Coold you prepare PR for this with test?

@mrtnzlml

This comment has been minimized.

Copy link
Contributor

@mrtnzlml mrtnzlml commented Sep 25, 2016

I implemented it differently. But in fact it's quite similar to the @f3l1x solution. The only difference is that my solution doesn't use setter. And even though I believe that it's better without setter, I'm not sure about my implementation. Usage:

services:
    latte.templateFactory:
        arguments:
            templateClassName: App\CustomTemplateImplementation

Unfortunately Template cannot be service (or at least I don't know how to do it properly - and I tried).

@f3l1x

This comment has been minimized.

Copy link
Member Author

@f3l1x f3l1x commented Sep 25, 2016

Maybe it's little bit confusing name Template Factory, but I don't know better. What about new concept?

  • LatteFactory - creates latte engine
  • TemplateClassFactory - creates just Template class (depends on TemplateFactory)
  • TemplateFactory - creates TemplateFactory via LatteFactory and TemplateClassFactory

  • LatteFactory
  • TemplatingFactory
  • TemplateFactory

Maybe?

@mrtnzlml

This comment has been minimized.

Copy link
Contributor

@mrtnzlml mrtnzlml commented Sep 25, 2016

Yeah, I was thinking about this approach but I want to know more opinions (from more people) first... :)

@TomasVotruba

This comment has been minimized.

Copy link

@TomasVotruba TomasVotruba commented Sep 25, 2016

Please discuss under PR #159, as it is suggested solution and it's more relevant there.
Thank you

@dg dg closed this in 2d565db Dec 20, 2016
dg added a commit that referenced this issue Dec 20, 2016
…oses #159][Closes #141]

With this change it's possible to simply use custom Template implementation. Usage example in config.neon:

latte:
    templateClass: App\CustomTemplateImplementation

Custom template  MUST extend Nette\Bridges\ApplicationLatte\Template.
dg added a commit that referenced this issue Dec 20, 2016
…oses #159][Closes #141]

With this change it's possible to simply use custom Template implementation. Usage example in config.neon:

latte:
    templateClass: App\CustomTemplateImplementation

Custom template  MUST extend Nette\Bridges\ApplicationLatte\Template.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.