Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

Added $templateFile to UI\Control#206

Open
holantomas wants to merge 2 commits intonette:master from
holantomas:master
Open

Added $templateFile to UI\Control #206
holantomas wants to merge 2 commits intonette:master from
holantomas:master

Conversation

@holantomas
Copy link

@holantomas holantomas commented Dec 10, 2018

  • new feature
  • BC break? no (3rd party apps maybe ...?)
  • doc PR: not needed

I made topic for this on forum: https://forum.nette.org/en/31591-ui-control-templatefile

mabar reacted with thumbs down emoji
Copy link
Contributor

mabar commented Dec 10, 2018

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) {
Copy link
Contributor

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.

Copy link
Author

@holantomas holantomas Dec 10, 2018

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.

Copy link
Contributor

@mabar mabar Dec 10, 2018
edited
Loading

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.

Copy link
Author

@holantomas holantomas Dec 10, 2018

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?

Copy link
Contributor

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.

Copy link
Author

@holantomas holantomas Dec 10, 2018

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.

Copy link
Author

holantomas commented Dec 10, 2018
edited
Loading

@mabar I'm OK with that 👍 If more people will consider it as good way I can try to implement it.

Copy link
Contributor

mabar commented Dec 10, 2018

I think you cannot as it requires more than ITemplate interface

Copy link
Member

milo commented Dec 11, 2018

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 render() method.

Why do you need set template file outside of Control?

Copy link
Author

holantomas commented Dec 11, 2018
edited
Loading

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 render() method.

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:
Control::getTemplate(): ITemplate is public
ITemplate::setFile() is public
This doesn't break anything.

And I'm not sure but settings template file in render() is to prevent unnecessary creating template or prevent creating template before Control is attached to presenter I think. Both doing my PR too.

@dg dg force-pushed the master branch 8 times, most recently from 10a5830 to e402814 Compare February 10, 2019 17:46
@dg dg force-pushed the master branch 3 times, most recently from 56c5e11 to 5919611 Compare February 13, 2019 00:53
@dg dg force-pushed the master branch 5 times, most recently from 1617426 to bea304e Compare March 12, 2019 00:51
@dg dg force-pushed the master branch 5 times, most recently from e4610ae to 5a520b1 Compare April 1, 2019 22:11
@dg dg force-pushed the master branch 3 times, most recently from 3463b9a to ee24f8e Compare June 19, 2025 16:47
@dg dg force-pushed the master branch 4 times, most recently from ddf16b5 to 87e4597 Compare July 17, 2025 22:42
@dg dg force-pushed the master branch 10 times, most recently from c62f26c to e72b735 Compare November 30, 2025 23:13
@dg dg force-pushed the master branch 3 times, most recently from f536135 to 4e8f41d Compare December 23, 2025 22:32
@dg dg force-pushed the master branch 2 times, most recently from c478b71 to 44181e2 Compare December 28, 2025 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@mabar mabar mabar left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /