Skip to content

Commit 255c876

Browse files
authored
Merge pull request plone#1203 from plone/classic-ui-icons
Update icons chapter
2 parents fd93780 + 81ad70e commit 255c876

File tree

2 files changed

+68
-54
lines changed

2 files changed

+68
-54
lines changed

docs/classic-ui/icons.md

Lines changed: 66 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
html_meta:
3-
"description": ""
4-
"property=og:description": ""
5-
"property=og:title": ""
6-
"keywords": ""
3+
"description": "Icon registration and resolving in Plone Classic UI"
4+
"property=og:description": "Icon registration and resolving in Plone Classic UI"
5+
"property=og:title": "Icon registration and resolving"
6+
"keywords": "Plone, Classic UI, classic-ui, icons, svg"
77
---
88

99
(classic-ui-icons-label)=
1010

11-
# Icons in Plone 6 Classic UI
11+
# Icons
1212

1313
This sections describes how to work with icons in Plone 6 Classic UI.
1414
Examples include the following.
@@ -35,99 +35,112 @@ See the file [package.json](https://github.com/plone/plone.staticresources/blob/
3535
## Registration
3636

3737
Icons are registered in Plone's registry.
38-
This provides an option to customize the contenttype and Plone UI icons by overriding icons via XML.
38+
This provides an option to customize the content type and Plone UI icons by overriding icons via XML.
39+
Plone ships with the following icon registrations by default.
3940

40-
- [Bootstrap icons](https://github.com/plone/plone.staticresources/blob/master/src/plone/staticresources/profiles/default/registry/icons_bootstrap.xml)
41-
- [contenttypes](https://github.com/plone/plone.staticresources/blob/master/src/plone/staticresources/profiles/default/registry/icons_contenttype.xml)
42-
- [Plone UI](https://github.com/plone/plone.staticresources/blob/master/src/plone/staticresources/profiles/default/registry/icons_plone.xml)
41+
- [Bootstrap](https://github.com/plone/plone.staticresources/blob/master/src/plone/staticresources/profiles/default/registry/icons_bootstrap.xml)
42+
- [Content Type](https://github.com/plone/plone.staticresources/blob/master/src/plone/staticresources/profiles/default/registry/icons_contenttype.xml)
43+
- [Mimetype](https://github.com/plone/plone.staticresources/blob/master/src/plone/staticresources/profiles/default/registry/icons_mimetype.xml)
44+
- [Language Flags](https://github.com/plone/plone.staticresources/blob/master/src/plone/staticresources/profiles/default/registry/icons_language_flags.xml)
45+
- [Country Flags](https://github.com/plone/plone.staticresources/blob/master/src/plone/staticresources/profiles/default/registry/icons_country_flags.xml)
46+
- [Plone](https://github.com/plone/plone.staticresources/blob/master/src/plone/staticresources/profiles/default/registry/icons_plone.xml)
47+
- [Toolbar](https://github.com/plone/plone.staticresources/blob/master/src/plone/staticresources/profiles/default/registry/icons_plone.xml)
48+
49+
The icons above are made available as Plone resources.
50+
For example, the icon registered as `lightning` (in XML with prefix full name is `plone.icon.lighting`) resource path is `++plone++bootstrap-icons/lightning.svg`.
51+
One could register another icon set under a new name, for example `++plone++fontawesome-icons`, and override the registrations above to use them.
4352

4453

4554
(classic-ui-icons-contextual-icons-label)=
4655

4756
## Contextual Icons
4857

49-
We can define contextual icons to be used in specific places in a website while preserving the default system icons to be used elsewhere throughout the site.
50-
To use a different icon than the system default, you would override it without touching the system icon.
51-
52-
You should avoid replacing system icons because it may result in an inconsistent user interface.
53-
54-
The specific icon name is based on the usage in the system.
55-
For example the copy icon is named `plone.icon.plone-copy`.
58+
Plone defines contextual icons, which are used in specific places in a website.
59+
For example we have an icon registered under the name `plone.icon.plone-copy` in https://github.com/plone/plone.staticresources/blob/master/src/plone/staticresources/profiles/default/registry/icons_plone.xml which points to the bootstrap `clipboard-plus` icon `++plone++bootstrap-icons/clipboard-plus.svg`.
60+
To use a different icon than the system default, you can override the registration for `plone.icon.plone-copy` with another icon path.
5661

5762

5863
(classic-ui-icons-icon-expression-label)=
5964

6065
## Icon expression
6166

62-
- The field `icon_expression` is used again to define icons for actions, contenttypes, and other purposes.
63-
- Use the icon name for icon expressions.
64-
65-
66-
(classic-ui-icons-customization-label)=
67-
68-
## Customization
69-
70-
```{todo}
71-
Add content for this section
72-
```
73-
74-
- Add custom icons
75-
- Override some of the icons
76-
77-
78-
(classic-ui-icons-icon-font-label)=
79-
80-
## Icon font
81-
8267
```{todo}
83-
Add content for this section
68+
How does this work? We need an example here!
8469
```
8570

86-
- Set up a profile to install the icon font.
87-
- Use Font Awesome as an example.
71+
- The field `icon_expression` is used again to define icons for actions, contenttypes, and other purposes.
72+
- Use the icon name for icon expressions.
8873

8974

9075
(classic-ui-icons-iconresolver-label)=
9176

9277
## Iconresolver
9378

94-
```{todo}
95-
What is `iconresolver`?
96-
Add to Glossary.
79+
The iconresolver take's an icon name (without the `plone.icon.` prefix) like `plone-copy` or `align-center` and resolves it to an actual icon.
80+
81+
```
82+
http://localhost:8080/Plone/@@iconresolver/plone-copy
83+
http://localhost:8080/Plone/@@iconresolver/align-center
9784
```
9885

86+
The iconresolver can be used via URL or via Python as shown in section {ref}`classic-ui-icons-iconresolver-get-icon-url-label` and {ref}`classic-ui-icons-iconresolver-get-icon-tag-label`.
87+
9988

10089
(classic-ui-icons-iconresolver-get-icon-url-label)=
10190

102-
### Get Icon URL
91+
### Get icon URL via Python expression
10392

104-
URL method of `@@icons` view returns the actual URL to the SVG icon.
105-
This can be used in an HTML `img` tag, for example.
93+
The `url` method of the `@@iconresolver` view returns the actual URL to the SVG icon.
94+
The icon resolver view is globally available in templates under the name `icons`.
95+
This can be used in a template for an `img` tag:
10696

10797
```xml
108-
<img src="" tal:attributes="src python:icons.url('alarm')" class="custom-class" alt="foo" />
98+
<img class="custom-class"
99+
alt="foo"
100+
src="${python:icons.url('alarm')}" />
109101
```
110102

111103

112104
(classic-ui-icons-iconresolver-get-icon-tag-label)=
113105

114-
### Get Icon Tag
106+
### Get an inline icon (tag) via Python expression
115107

116108
The tag method is used with `tal:replace`.
117109
It returns an SVG image.
118110
Inline icons can be styled via CSS.
119-
`tag_class` and `tag_alt` is used to pass in custom classes and an `alt` text.
111+
`tag_class` and `tag_alt` are used to pass in custom classes and an `alt` text.
120112

121113
```xml
122-
<tal:icon tal:replace="structure python:icons.tag('archive', tag_class='custom-class', tag_alt='foobar')" />
114+
<tal:icon
115+
tal:replace="structure python:icons.tag('alarm')" />
116+
117+
<tal:icon
118+
tal:replace="structure python:icons.tag('archive', tag_class='custom-class', tag_alt='foobar')" />
119+
```
120+
121+
### Get inline icon (tag) in a template via traverse
122+
123+
```xml
124+
<tal:icon tal:replace="structure icons/alarm" />
125+
```
126+
127+
### Get an inline icon (tag) in JavaScript
128+
129+
```js
130+
const baseUrl = $("body").attr("data-portal-url");
131+
let icon = null;
132+
if(baseUrl){
133+
const url = baseUrl + "/@@iconresolver";
134+
if (url) {
135+
const resp = await fetch(`${url}/${name}`);
136+
icon = await resp.text();
137+
}
138+
}
123139
```
124140

125-
(classic-ui-icons-iconresolver-resource-path-label)=
141+
[Mockup](https://github.com/plone/mockup) provides an `iconResolver` function, defined in `core/utils.js`, which does this the same way and has a fallback for demo and testing.
126142

127-
### Resource Path
128143

129-
SVG files are available from the resource path.
130-
For example, the lightning icon's resource path is `++plone++bootstrap-icons/lightning.svg`.
131144

132145

133146
(classic-ui-icons-iconresolver-fallback-label)=

docs/classic-ui/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ This chapter is a developer reference manual for working with Classic UI.
4747
```{toctree}
4848
:maxdepth: 2
4949
50-
static-resources
5150
theming/index
51+
static-resources
5252
templates
53+
templates-global-variables
5354
views
5455
viewlets
5556
forms

0 commit comments

Comments
 (0)