Skip to content

Commit 38be3c7

Browse files
authored
Merge pull request plone#1441 from plone/classic-ui-static-resources-registry
add docs for static js and css resource registry
2 parents 3feec82 + 171cd62 commit 38be3c7

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

docs/classic-ui/static-resources.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,80 @@ We often want to ship a website with a static resource, such as an image, icon,
1515
For this, we need to register static resources.
1616

1717

18+
(classic-ui-static-resources-registering-label)=
19+
## Registering javascript and css
20+
21+
To register a static resource in Plone 6, we need to use the `plone.base.interfaces.resources.IBundleRegistry` interface.
22+
23+
The following example registers a Javascript resource in `browser/profiles/default/registry` of your Plone 6 project.
24+
The js files have to be in the `browser/static` folder of your Plone 6 project.
25+
26+
```xml
27+
<registry>
28+
<records interface="plone.base.interfaces.resources.IBundleRegistry" prefix="plone.bundles/jscript">
29+
<value key="enabled">True</value>
30+
<value key="jscompilation">++plone++myproject.site/javascript.min.js</value>
31+
<value key="load_async">False</value>
32+
<value key="load_defer">False</value>
33+
<value key="depends">plone</value>
34+
</records>
35+
</registry>
36+
```
37+
38+
You can register a CSS resource in the same way.
39+
40+
```xml
41+
<registry>
42+
<records interface="plone.base.interfaces.resources.IBundleRegistry" prefix="plone.bundles/css">
43+
<value key="enabled">True</value>
44+
<value key="csscompilation">++plone++myproject.site/style.min.css</value>
45+
<value key="depends">plone</value>
46+
</records>
47+
</registry>
48+
```
49+
50+
Registering a js file and a css file in the same bundle is also possible.
51+
52+
```xml
53+
<registry>
54+
<records interface="plone.base.interfaces.resources.IBundleRegistry" prefix="plone.bundles/css">
55+
<value key="enabled">True</value>
56+
<value key="csscompilation">++plone++myproject.site/style.min.css</value>
57+
<value key="jscompilation">++plone++myproject.site/javascript.min.js</value>
58+
<value key="load_async">False</value>
59+
<value key="load_defer">False</value>
60+
<value key="depends">plone</value>
61+
</records>
62+
</registry>
63+
```
64+
1865
(classic-ui-static-resources-available-attributeslabel)=
1966

2067
## Available attributes
2168

69+
The following attributes are available for registering a static resource:
70+
71+
`enabled`
72+
: Whether the bundle is enabled or not. If it is disabled, the bundle will not be loaded.
73+
74+
`jscompilation`
75+
: The path to the compiled js file.
76+
77+
`csscompilation`
78+
: The path to the compiled css file.
79+
80+
`depends`
81+
: A list of bundles that this bundle depends on.
82+
83+
`load_async`
84+
: Whether the bundle should be loaded asynchronously or not. *Only JS*
85+
86+
`load_defer`
87+
: Whether the bundle should be loaded deferred or not. *Only JS*
88+
2289

2390
(classic-ui-static-resources-loading-order-label)=
2491

2592
## Loading order of resources
2693

94+
`depends` is used to define the loading order of resources, by specifying the name of the depending bundle.

docs/install/manage-add-ons-packages.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ make start-backend
147147
```
148148

149149
```{seealso}
150-
See the [documentation of `mxdev` in its README.rst](https://github.com/mxstack/mxdev/blob/main/README.rst) for complete information.
150+
See the [documentation of `mxdev` in its README.md](https://github.com/mxstack/mxdev/blob/main/README.md) for complete information.
151151
```
152152

153153

0 commit comments

Comments
 (0)