-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
Added $templateFile to UI\Control #206
base: master
Are you sure you want to change the base?
Conversation
I prefer a higher level abstraction which would use views instead of specific templates, similarly like presenters do. |
{ | ||
$this->templateFile = $templateFile; | ||
|
||
if ($this->template !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conditional setter? Never seen that before. Should throw exception or create template if not already created.
I understand why it's here, but it's a just a very specific usecase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if you got it right. Whole idea of this PR is to be able setup file without creating template. If we throw exception or create template there is no PR needed any more, cause it will work just like shortcut for $control->getTemplate()->setFile()
.
But I thought about it if I should add this condition. Because it's just for specific usecase as you said when user try to set file after template was created to prevent "WTF?" situations and let setter work like user expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said, I understand. But imagine you don't know that code, just api. It looks exactly like a shortcut, but acts absolutely different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't, I'm not saying you're not right, but I think user don't care about it, he just want to set template file/view and this did that without unnecessary loads.
And I really hate setting template in $onAnchor
event. Or do you know way how to do it without event in control factory or in createComponent<name>()
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could configure template file through it's factory definition
fooControlFactory:
implement IFooControlFactory
setup:
- getTemplate()->setFile('/path/to/file')
But I never used that approach. I have ITemplate with setView method and to change path to these views I only need change pattern in configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will end with InvalidStateException
or new template instance. Anyway I don't like to setup file template in config, there are situations where you want to setup view by condition, or you have one control with factory and want to setup many different view for actual page.
@mabar I'm OK with that 👍 If more people will consider it as good way I can try to implement it. |
I think you cannot as it requires more than ITemplate interface |
IMHO, template file is internal thing of Control, thing of encapsulation. Control may use more templates too, that's why you usualy set template file in Why do you need set template file outside of Control? |
It's shown in forum topic. User usign 3rd party control like datagrid or paginator but HTML not equal to his UI for example. encapsulation: And I'm not sure but settings template file in |
10a5830
to
e402814
Compare
56c5e11
to
5919611
Compare
1617426
to
bea304e
Compare
e4610ae
to
5a520b1
Compare
e3d05b3
to
929a242
Compare
426e735
to
c19ebdc
Compare
2b9da37
to
30d90f4
Compare
bf86204
to
c91f90a
Compare
57bd587
to
e908315
Compare
c5ecbda
to
ecb200c
Compare
I made topic for this on forum: https://forum.nette.org/en/31591-ui-control-templatefile