Skip to content

Commit eb2973f

Browse files
committed
Update icons chapter
1 parent 6d5c46f commit eb2973f

File tree

2 files changed

+67
-53
lines changed

2 files changed

+67
-53
lines changed

docs/classic-ui/icons.md

Lines changed: 65 additions & 52 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 contenttype and Plone UI icons by overriding icons via XML. Plone ships with the following icon registrations by default.
3939

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)
40+
- [Bootstrap](https://github.com/plone/plone.staticresources/blob/master/src/plone/staticresources/profiles/default/registry/icons_bootstrap.xml)
41+
- [Content Type](https://github.com/plone/plone.staticresources/blob/master/src/plone/staticresources/profiles/default/registry/icons_contenttype.xml)
42+
- [Mimetype](https://github.com/plone/plone.staticresources/blob/master/src/plone/staticresources/profiles/default/registry/icons_mimetype.xml)
43+
- [Language Flags](https://github.com/plone/plone.staticresources/blob/master/src/plone/staticresources/profiles/default/registry/icons_language_flags.xml)
44+
- [Country Flags](https://github.com/plone/plone.staticresources/blob/master/src/plone/staticresources/profiles/default/registry/icons_country_flags.xml)
45+
- [Plone](https://github.com/plone/plone.staticresources/blob/master/src/plone/staticresources/profiles/default/registry/icons_plone.xml)
46+
- [Toolbar](https://github.com/plone/plone.staticresources/blob/master/src/plone/staticresources/profiles/default/registry/icons_plone.xml)
47+
48+
The icons above are made available as plone resources.
49+
For example, the lightning icon's resource path is `++plone++bootstrap-icons/lightning.svg`. One could register another icon set under a new name, for example `++plone++fontawesome-icons` and override the registrations above to use them.
4350

4451

4552
(classic-ui-icons-contextual-icons-label)=
4653

4754
## Contextual Icons
4855

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`.
56+
Plone defines contextual icons, which are used in specific places in a website.
57+
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`.
58+
To use a different icon than the system default, you can override the registration for `plone.icon.plone-copy` with another icon path.
5659

5760

5861
(classic-ui-icons-icon-expression-label)=
5962

6063
## Icon expression
6164

65+
```{note}
66+
How does this work? We need an example here!
67+
```
68+
6269
- The field `icon_expression` is used again to define icons for actions, contenttypes, and other purposes.
6370
- Use the icon name for icon expressions.
6471

6572

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-
73+
(classic-ui-icons-iconresolver-label)=
7774

78-
(classic-ui-icons-icon-font-label)=
75+
## Iconresolver
7976

80-
## Icon font
77+
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.
8178

82-
```{todo}
83-
Add content for this section
79+
```
80+
http://localhost:8080/Plone/@@iconresolver/plone-copy
8481
```
8582

86-
- Set up a profile to install the icon font.
87-
- Use Font Awesome as an example.
88-
89-
90-
(classic-ui-icons-iconresolver-label)=
91-
92-
## Iconresolver
93-
94-
```{todo}
95-
What is `iconresolver`?
96-
Add to Glossary.
9783
```
84+
http://localhost:8080/Plone/@@iconresolver/align-center
85+
```
86+
87+
It can be used via URL or via Python as shown below.
9888

9989

10090
(classic-ui-icons-iconresolver-get-icon-url-label)=
10191

102-
### Get Icon URL
92+
### Get icon URL via Python expression
10393

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.
94+
The `url` method of `@@iconresolver` view returns the actual url to the SVG icon. The iconresolver 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.
119111
`tag_class` and `tag_alt` is 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)