Add support for inline output with block => false#2
Conversation
When passing `block => false` option to script() or css() methods, the helper now outputs tags directly instead of buffering to view blocks. This is consistent with CakePHP's Html helper behavior and allows for inline asset rendering in templates without using view blocks. Changes: - script(): Echo output when block is false, handle preload tags inline - css(): Echo output when block is false - addDependentCss(): Support inline parameter for dependent CSS Fixes TypeError when passing block => false (previously crashed with "Argument #1 ($name) must be of type string, false given").
|
thanks! There also seem to be some other test failures that should be handled ? |
|
You need to allow this in the settings. Then i can click the button :) |
It should be good for new work by you. It seems that this setting is for "new contributors to the project" |
|
Allow updating in PR or sth |
think its okay how it is configured now. It should start the worlflow automatically for new commits on this branch |
|
Thats a different setting. The updste Button is a different one. Its not the one about permission. |
|
Right, done! |
Change script() and css() methods to return the tag string when block => false, instead of echoing directly. This is more consistent with CakePHP's HtmlHelper conventions and makes the code easier to test.
9f6c867 to
675a3e0
Compare
|
I cleaned up the approach. Now it looks good. |
|
maybe just add a little entry about $block in the docs? |
|
The actual issue I see is in development mode: every Would you consider a small follow-up to deduplicate |
There was a problem hiding this comment.
Pull request overview
Adds inline rendering support to the CakeVite ViteHelper so callers can pass block => false to get generated <script>/<link> tags back as a string (instead of appending to view blocks), aligning behavior with CakePHP’s HtmlHelper and fixing the prior View::append(false, ...) crash.
Changes:
- Update
ViteHelper::script()andViteHelper::css()to return?string(string whenblock === false, otherwisenull). - Update dependent CSS handling so it can be returned inline when inline mode is enabled.
- Add README documentation and PHPUnit coverage for inline output scenarios (dev + production, preload tags, dependent CSS).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/View/Helper/ViteHelper.php |
Implements inline output return values for script()/css() and adjusts dependent CSS handling to support inline mode. |
tests/TestCase/View/Helper/ViteHelperTest.php |
Adds tests asserting inline output is returned and that view blocks remain empty when block => false. |
README.md |
Documents the new “Inline Output” behavior and adds it to the table of contents. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ge cases - Add viteClientRendered tracking to ViteHelper to prevent duplicate @vite/client output - Update AssetService to support skipViteClient option - Fix pluginScript/pluginCss to return ?string for inline mode (block => false) - Fix addDependentCss to skip CSS when cssBlock is false and not in inline mode - Add tests for deduplication and plugin inline output - Document deduplication and cssBlock behavior in README
|
Done! Added the @vite/client deduplication to this PR along with docs updates. Changes:
|
|
thanks! |

Summary
When passing
block => falseoption toscript()orcss()methods, the helper now returns the tags as a string instead of buffering to view blocks.This is consistent with CakePHP's Html helper behavior and allows for inline asset rendering in templates.
Bug fixed: Previously passing
block => falsewould crash with:Changes
script(): Returns?string- tag string when block is false, null otherwisecss(): Returns?string- tag string when block is false, null otherwiseaddDependentCss(): Returns dependent CSS tags when inline mode is enabledUse Case
This enables inline asset loading in view elements:
Tests
testScriptWithBlockFalseOutputsInlinetestScriptWithBlockFalseInProductionModetestCssWithBlockFalseOutputsInlinetestCssWithBlockFalseInProductionModetestScriptWithBlockFalseOutputsPreloadTagsInlinetestScriptWithBlockFalseOutputsDependentCssInline