-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Enhancement for template response #1167
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
Conversation
Added the capability of passing required scripts and styles to the template response.
|
@janis91, thanks for your PR! By analyzing the annotation information on this pull request, we identified @MorrisJobke, @BernhardPosselt and @DeepDiver1975 to be potential reviewers |
|
What would scripts look like? |
|
full example: $styles = [
'vendor' => ['select2/select2'],
'app' => [
'nextnotes' => [
'font-awesome.min',
'simplemde.min',
'markdown.min',
'style',
],
],
];
$scripts = [
'vendor' => ['select2/select2'],
'app' => [
'nextnotes' => [
'notes',
'tags',
'view',
'app',
],
],
];
new TemplateResponse('nextnotes', 'main', [], 'user', $styles, $scripts); |
|
Hm I'd say the idea is good but that's one giant constructor. Think of inlining everything ;D What about combining both arrays in another array, so instead of $scripts, $styles, $htmlImports, ... we would simply pass something like $assets where $assets is: [
'scripts' => ...
'styles' => ...
... |
|
Thanks for the PR @janis91 seeing it now. I'm not a big fan of magic arrays to pass to constructors.
That might make it more explicit and a bit more abstract? |
|
I could remove it from the constructor and add functions for every case. But recently I recognized the style and script functions in /lib/private/legacy/template/functions.php. Maybe we have to discuss if the approach proposed here is really a step forward? |
added as functions.
|
Hi, can you add labels to this PR to have a better clarity if it is a WIP or a complete PR? |
|
@rullzer Anything new? |
| * @param string $renderAs how the page should be rendered, defaults to user | ||
| * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0 | ||
| * @param array $styles an array of styles which sould be added to the template | ||
| * @param array $scripts an array of scripts which should be added to the template |
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 then needs to be removed.
|
Mmmm I'm still not really sure here. |
|
Yeah I am with you! |
|
FYI I found this idea to be a quite interesting take on templates https://r.je/transphporm-php-templates.html Not saying that we should adopt it but its interesting |
|
Ok lets close this then. Thnaks for the link @BernhardPosselt |
As discussed in #889 , I added the capability for passing required scripts and styles to the template response. The scripts and styles will be added to the template after that.
An example constructor call (scripts work the same):
I will provide the tests, if this is what you were expecting @rullzer.