| 1 |
--- |
| 2 |
title: css.Quoted |
| 3 |
description: Returns the given string, setting its data type to indicate that it must be quoted when used in CSS. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [] |
| 9 |
returnType: css.QuotedString |
| 10 |
signatures: [css.Quoted STRING] |
| 11 |
--- |
| 12 |
|
| 13 |
> [!NOTE] |
| 14 |
> This function is only applicable to the `vars` option passed to the [`css.Build`][] or [`css.Sass`][] functions. |
| 15 |
|
| 16 |
When passing a `vars` map to the `css.Sass` function, Hugo detects common typed CSS values such as `24px` or `#FF0000` using regular expression matching. If necessary, you can bypass automatic type inference by using the `css.Quoted` function to explicitly indicate that the value must be treated as a quoted string. |
| 17 |
|
| 18 |
For the `css.Build` function, use `css.Quoted` to explicitly indicate that a value must be treated as a quoted string, most commonly for `font-family` names or the `content` property. |
| 19 |
|
| 20 |
In the example below, we use `css.Quoted` to ensure the values for the `content` property are injected as strings. |
| 21 |
|
| 22 |
```go-html-template |
| 23 |
{{ $vars := dict |
| 24 |
"ol-li-after" ("6" | css.Quoted) |
| 25 |
"ul-li-after" ("7" | css.Quoted) |
| 26 |
}} |
| 27 |
|
| 28 |
{{ $opts := dict "vars" $vars "transpiler" "dartsass" }} |
| 29 |
{{ with resources.Get "sass/main.scss" | css.Sass $opts }} |
| 30 |
<link rel="stylesheet" href="{{ .RelPermalink }}"> |
| 31 |
{{ end }} |
| 32 |
``` |
| 33 |
|
| 34 |
Using the `hugo:vars` identifier in your stylesheet: |
| 35 |
|
| 36 |
```scss |
| 37 |
@use "hugo:vars" as h; |
| 38 |
|
| 39 |
ol li::after { |
| 40 |
content: h.$ol-li-after; |
| 41 |
} |
| 42 |
|
| 43 |
ul li::after { |
| 44 |
content: h.$ul-li-after; |
| 45 |
} |
| 46 |
``` |
| 47 |
|
| 48 |
The resulting CSS contains quoted strings: |
| 49 |
|
| 50 |
```css |
| 51 |
ol li::after { |
| 52 |
content: "6"; |
| 53 |
} |
| 54 |
|
| 55 |
ul li::after { |
| 56 |
content: "7"; |
| 57 |
} |
| 58 |
``` |
| 59 |
|
| 60 |
[`css.Build`]: /functions/css/build/#vars |
| 61 |
[`css.Sass`]: /functions/css/sass/#vars |