You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/reference/template-tag.md
+44-5
Original file line number
Diff line number
Diff line change
@@ -195,16 +195,30 @@ Your PyScript component file requires a `#!python def root()` component to funct
195
195
196
196
??? question "How do I execute JavaScript within PyScript components?"
197
197
198
-
PyScript components have the ability to directly execute JavaScript using the [`pyodide` `js` module](https://pyodide.org/en/stable/usage/type-conversions.html#importing-javascript-objects-into-python) or [`pyscript` foreign function interface](https://docs.pyscript.net/2024.6.1/user-guide/dom/).
198
+
PyScript components have the ability to directly execute standard library JavaScript using the [`pyodide` `js` module](https://pyodide.org/en/stable/usage/type-conversions.html#importing-javascript-objects-into-python) or [`pyscript` foreign function interface](https://docs.pyscript.net/2024.6.1/user-guide/dom/).
199
199
200
-
_The `#!python js` module has access to everything within the browser's JavaScript environment. Therefore, any public JavaScript functions loaded within your HTML `#!html <head>` can be called as well. However, be mindful of JavaScript load order!_
200
+
The `#!python js` module has access to everything within the browser's JavaScript environment. Therefore, any global JavaScript functions loaded within your HTML `#!html <head>` can be called as well. However, be mindful of JavaScript load order!
201
201
202
202
=== "root.py"
203
203
204
204
```python
205
205
{% include "../../examples/python/pyscript-js-execution.py" %}
206
206
```
207
207
208
+
To import JavaScript modules in a fashion similar to `#!javascript import {moment} from 'static/moment.js'`, you will need to configure your `#!jinja {% pyscript_setup %}` block to make the module available to PyScript. This module will be accessed within `#!python pyscript.js_modules.*`. For more information, see the [PyScript JS modules docs](https://docs.pyscript.net/2024.6.2/user-guide/configuration/#javascript-modules).
209
+
210
+
=== "root.py"
211
+
212
+
```python
213
+
{% include "../../examples/python/pyscript-js-module.py" %}
214
+
```
215
+
216
+
=== "my_template.html"
217
+
218
+
```jinja
219
+
{% include "../../examples/html/pyscript-js-module.html" %}
220
+
```
221
+
208
222
<!--pyscript-js-exec-end-->
209
223
210
224
<!--pyscript-multifile-start-->
@@ -297,12 +311,13 @@ You can optionally include a list of Python packages to install within the PyScr
297
311
298
312
| Name | Type | Description | Default |
299
313
| --- | --- | --- | --- |
300
-
| `#!python *dependencies` | `#!python str` | Dependencies that need to be loaded on the page for your PyScript components. Each dependency must be contained within it's own string and written in Python requirements file syntax. | N/A |
314
+
| `#!python *extra_py` | `#!python str` | Dependencies that need to be loaded on the page for your PyScript components. Each dependency must be contained within it's own string and written in Python requirements file syntax. | N/A |
315
+
| `#!python extra_js` | `#!python str | dict` | A JSON string or Python dictionary containing a vanilla JavaScript module URL and the `#!python name: str` to access it within `#!python pyscript.js_modules.*`. | `#!python ""` |
??? question "How do I define dependencies for my PyScript component?"
318
+
??? question "How do I install additional Python dependencies?"
304
319
305
-
Dependencies must be available on [`pypi`](https://pypi.org/), written in pure Python, and declared in your `#!jinja {% pyscript_setup %}` block using Python requirements file syntax.
320
+
Dependencies must be available on [`pypi`](https://pypi.org/) and declared in your `#!jinja {% pyscript_setup %}` block using Python requirements file syntax.
306
321
307
322
These dependencies are automatically downloaded and installed into the PyScript client-side environment when the page is loaded.
308
323
@@ -312,6 +327,30 @@ You can optionally include a list of Python packages to install within the PyScr
312
327
{% include "../../examples/html/pyscript-setup-dependencies.html" %}
313
328
```
314
329
330
+
??? question "How do I install additional Javascript dependencies?"
331
+
332
+
You can use the `#!python extra_js` keyword to load additional JavaScript modules into your PyScript environment.
333
+
334
+
=== "my_template.html"
335
+
336
+
```jinja
337
+
{% include "../../examples/html/pyscript-setup-extra-js-object.html" %}
338
+
```
339
+
340
+
=== "views.py"
341
+
342
+
```python
343
+
{% include "../../examples/python/pyscript-setup-extra-js-object.py" %}
344
+
```
345
+
346
+
The value for `#!python extra_js` is most commonly a Python dictionary, but JSON strings are also supported.
347
+
348
+
=== "my_template.html"
349
+
350
+
```jinja
351
+
{% include "../../examples/html/pyscript-setup-extra-js-string.html" %}
352
+
```
353
+
315
354
??? question "How do I modify the `pyscript` default configuration?"
316
355
317
356
You can modify the default [PyScript configuration](https://docs.pyscript.net/2024.6.2/user-guide/configuration/) by providing a value to the `#!python config` keyword.
0 commit comments