|
| 1 | +--- |
| 2 | +myst: |
| 3 | + html_meta: |
| 4 | + "description": "Diazo themes can be managed programmatically through the @themes endpoint in a Plone site." |
| 5 | + "property=og:description": "Diazo themes can be managed programmatically through the @themes endpoint in a Plone site." |
| 6 | + "property=og:title": "Themes" |
| 7 | + "keywords": "Plone, plone.restapi, REST, API, Themes, Diazo" |
| 8 | +--- |
| 9 | + |
| 10 | +# Themes |
| 11 | + |
| 12 | +Diazo themes can be managed programmatically through the `@themes` endpoint in a Plone site. |
| 13 | +This endpoint requires `plone.app.theming` to be installed and the `cmf.ManagePortal` permission. |
| 14 | + |
| 15 | +It is particularly useful in containerized deployments (such as Kubernetes) where access to the Plone UI may not be available. |
| 16 | + |
| 17 | +## Listing themes |
| 18 | + |
| 19 | +A list of all available themes can be retrieved by sending a `GET` request to the `@themes` endpoint: |
| 20 | + |
| 21 | +```{eval-rst} |
| 22 | +.. http:example:: curl httpie python-requests |
| 23 | + :request: ../../../src/plone/restapi/tests/http-examples/themes_get_list.req |
| 24 | +``` |
| 25 | + |
| 26 | +Response: |
| 27 | + |
| 28 | +```{literalinclude} ../../../src/plone/restapi/tests/http-examples/themes_get_list.resp |
| 29 | +:language: http |
| 30 | +``` |
| 31 | + |
| 32 | +The following fields are returned for each theme: |
| 33 | + |
| 34 | +- `@id`: hypermedia link to the theme resource |
| 35 | +- `id`: the theme identifier |
| 36 | +- `title`: the friendly name of the theme |
| 37 | +- `description`: description of the theme |
| 38 | +- `active`: whether this theme is currently active |
| 39 | +- `preview`: path to the theme preview image (or `null`) |
| 40 | +- `rules`: path to the theme rules file |
| 41 | + |
| 42 | +## Reading a theme |
| 43 | + |
| 44 | +A single theme can be retrieved by sending a `GET` request with the theme ID as a path parameter: |
| 45 | + |
| 46 | +```{eval-rst} |
| 47 | +.. http:example:: curl httpie python-requests |
| 48 | + :request: ../../../src/plone/restapi/tests/http-examples/themes_get.req |
| 49 | +``` |
| 50 | + |
| 51 | +Response: |
| 52 | + |
| 53 | +```{literalinclude} ../../../src/plone/restapi/tests/http-examples/themes_get.resp |
| 54 | +:language: http |
| 55 | +``` |
| 56 | + |
| 57 | +## Uploading a theme |
| 58 | + |
| 59 | +A new theme can be uploaded by sending a `POST` request with a ZIP archive as `multipart/form-data`: |
| 60 | + |
| 61 | +```{eval-rst} |
| 62 | +.. http:example:: curl httpie python-requests |
| 63 | + :request: ../../../src/plone/restapi/tests/http-examples/themes_post.req |
| 64 | +``` |
| 65 | + |
| 66 | +Response: |
| 67 | + |
| 68 | +```{literalinclude} ../../../src/plone/restapi/tests/http-examples/themes_post.resp |
| 69 | +:language: http |
| 70 | +``` |
| 71 | + |
| 72 | +The following form fields are accepted: |
| 73 | + |
| 74 | +- `themeArchive` (required): the ZIP file containing the theme |
| 75 | +- `enable` (optional): set to `true` to activate the theme immediately after upload |
| 76 | +- `replace` (optional): set to `true` to overwrite an existing theme with the same ID |
| 77 | + |
| 78 | +## Activating a theme |
| 79 | + |
| 80 | +A theme can be activated by sending a `PATCH` request with `{"active": true}`: |
| 81 | + |
| 82 | +```{eval-rst} |
| 83 | +.. http:example:: curl httpie python-requests |
| 84 | + :request: ../../../src/plone/restapi/tests/http-examples/themes_patch_activate.req |
| 85 | +``` |
| 86 | + |
| 87 | +Response: |
| 88 | + |
| 89 | +```{literalinclude} ../../../src/plone/restapi/tests/http-examples/themes_patch_activate.resp |
| 90 | +:language: http |
| 91 | +``` |
| 92 | + |
| 93 | +## Deactivating a theme |
| 94 | + |
| 95 | +A theme can be deactivated by sending a `PATCH` request with `{"active": false}`: |
| 96 | + |
| 97 | +```{eval-rst} |
| 98 | +.. http:example:: curl httpie python-requests |
| 99 | + :request: ../../../src/plone/restapi/tests/http-examples/themes_patch_deactivate.req |
| 100 | +``` |
| 101 | + |
| 102 | +Response: |
| 103 | + |
| 104 | +```{literalinclude} ../../../src/plone/restapi/tests/http-examples/themes_patch_deactivate.resp |
| 105 | +:language: http |
| 106 | +``` |
0 commit comments