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
@@ -42,6 +51,40 @@ public InlineSvgTagHelper(MediaFileManager mediaFileManager, IWebHostEnvironment
42
51
[HtmlAttributeName("media-item")]
43
52
publicIPublishedContent?MediaItem{get;set;}
44
53
54
+
/// <summary>
55
+
/// A classic CSS class property to apply/append a CSS class or classes.
56
+
/// </summary>
57
+
[HtmlAttributeName("class")]
58
+
publicstring?CssClass{get;set;}
59
+
60
+
/// <summary>
61
+
/// A boolean to ensure a viewbox is present within the SVG tag to ensure the vector is always responsive.
62
+
/// NOTE: Use the appsettings configuration to apply this globally (e.g. "Our.Umbraco.TagHelpers": { "InlineSvgTagHelper": { "EnsureViewBox": true } } ).
63
+
/// </summary>
64
+
[HtmlAttributeName("ensure-viewbox")]
65
+
publicboolEnsureViewBox{get;set;}
66
+
67
+
/// <summary>
68
+
/// A boolean to cache the SVG contents rather than performing the operation on each page load.
69
+
/// NOTE: Use the appsettings configuration to apply this globally (e.g. "Our.Umbraco.TagHelpers": { "InlineSvgTagHelper": { "Cache": true } } ).
70
+
/// </summary>
71
+
[HtmlAttributeName("cache")]
72
+
publicboolCache{get;set;}
73
+
74
+
/// <summary>
75
+
/// An integer to set the cache minutes. Default: 180 minutes.
76
+
/// NOTE: Use the appsettings configuration to apply this globally (e.g. "Our.Umbraco.TagHelpers": { "InlineSvgTagHelper": { "CacheMinutes": 180 } } ).
77
+
/// </summary>
78
+
[HtmlAttributeName("cache-minutes")]
79
+
publicintCacheMinutes{get;set;}
80
+
81
+
/// <summary>
82
+
/// A boolean to ignore the appsettings.
83
+
/// NOTE: Applies to 'ensure-viewbox' & 'cache' only
Copy file name to clipboardExpand all lines: README.md
+33Lines changed: 33 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -182,11 +182,44 @@ If you do not specify a template and use `<our-lang-switcher />` it will use the
182
182
This tag helper element `<our-svg>` will read the file contents of an SVG file and output it as an inline SVG in the DOM.
183
183
It can be used in one of two ways, either by specifying the `src` attribute to a physcial static file served from wwwRoot or by specifying the `media-item` attribute to use a picked IPublishedContent Media Item.
184
184
185
+
### Basic usage:
185
186
```cshtml
186
187
<our-svg src="/assets/icon.svg" />
187
188
<our-svg media-item="@Model.Logo" />
188
189
```
189
190
191
+
### Advanced usage: *(as of version 1.x.x)
192
+
193
+
Additional properties have been added to cache the output and also to ensure the SVG contains a viewbox property instead of the width & height properties to aid in making the vector image responsive within a parent HTML element.
-`class` - Allows for a CSS class upon the SVG element. This is a `string` value.
200
+
-`ensure-viewbox` - Enables the feature to "fix" the output SVG which always ensures the SVG utilises a viewbox rather than width & height. This is a `boolean` value.
201
+
-`cache` - Enables the feature to cache the output at runtime level. This is a `boolean` value.
202
+
-`cache-minutes` - Defines the amount of time (in minutes) to cache the output. To be used in conjunction with the `cache` property. This is an `integer` value.
203
+
-`ignore-appsettings` - When enabled, the all settings appropiate to this tag helper which are defined within `appsettings.json` are completely ignored. For example, if global caching is enabled we can simply disable caching of individual elements (unless the `cache` property is `true`). This is a `boolean` value.
204
+
205
+
### Global settings via appsettings.json
206
+
207
+
Applying any of the below configurations within your `appsettings.json` file will apply global settings to all elements using this tag helper. See the `ignore-appsettings` to override these global settings at element level. The values shown below are the hard-coded default values.
208
+
209
+
{
210
+
"Our.Umbraco.TagHelpers": {
211
+
"OurSVG": {
212
+
"EnsureViewBox": false,
213
+
"Cache": false,
214
+
"CacheMinutes": 180
215
+
}
216
+
}
217
+
}
218
+
219
+
> **Note:** SVG caches are cleared on application restart, or by resaving the media in the media library.
220
+
221
+
222
+
190
223
## `<our-fallback>`
191
224
This tag helper element `<our-fallback>` uses the same fallback mode logic that is only available on the `Value()` method of the `IPublishedContent` interface that uses a string for the property name to lookup. In addition if the fallback value from a language or ancestors is not available we are still able to fallback to the content inside the tag.
0 commit comments