Finally getting my head around the web asset stuff.
Love that I can add one line to a component to add multiple scripts using the presets.
What I am missing (maybe it exists and I'm not skilled enough to see it) is the ability to use joomla language strings in the same way.
For example I have a preset that contains multiple scripts and stylesheets and it needs to use one language string. This currently means that I have to add that string to the component php as well ;(
// Attach all items from foobar preset to the document
$wa->usePreset('foobar');
// Grab any language strings that are needed in the preset
Text::script('JGLOBAL_COLUMNS');
Not too bad with one string but a real pia with multiple. It would be great to list them in the preset or similar
Labels |
Added:
No Code Attached Yet
|
Labels |
Added:
?
|
Actual example here for the form validation https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/WebAsset/AssetItem/FormValidateAssetItem.php with it's web asset definition
joomla-cms/build/media_source/system/joomla.asset.json
Lines 130 to 141 in 92529d1
But as @Fedik says this is the intended & documented solution for now. Happy if something more concrete as a proposal comes up to considering it - but closing this for now as it's definitely possible with the current code.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-01-06 00:05:18 |
Closed_By | ⇒ | wilsonge |
thanks
That would be a good feature, especially for complex clientside apps (like media manager).
Not sure how it should be implemented, maybe something like:
Text::scriptLanguageFile('blabla.script.ini')
which load whole file toText::script()
.At current state Developer can implement own
WebAsset
item class for the script, and load constants from there.The class should implement
WebAssetAttachBehaviorInterface
https://docs.joomla.org/J4.x:Web_Assets#Advanced:_Custom_WebAssetItem_classWith
onAttachCallback
method, that will callText::script
for all constants, not much nice but should work.Something like this: