화면을 이미지(모자)로 표시하는 테마 컴포넌트에서
scss에서 이미지를 사용하려면, about.json에 정의된 다음과 같은 이미지들을 자산 이름 그대로 사용하여 작동합니다.
{
"name": "christmas-decorations",
"about_url": "",
"license_url": "",
"author": "",
"assets": {
"red-hat1": "assets/decorations/red-hat1.png",
"red-hat2": "assets/decorations/red-hat2.png",
"squirrel2": "assets/decorations/squirrel2.png",
}
}
scss에서 이 이미지들을 사용하려면, 다음과 같이 자산 이름을 직접 사용하면 잘 작동합니다.
background: transparent url($red-hat1) top left no-repeat;
화면에 표시할 모자 이미지를 선택할 수 있는 설정을 추가하고 싶습니다.
settings.yml에는 다음과 같은 설정이 있어 화면에 표시할 모자 이미지를 선택합니다.
hat_type:
default: red-hat1
type: enum
choices:
- red-hat1
- red-hat2
- squirrel2
scss에서 if-else를 사용하여 이미지를 적용할 수는 있지만, 이 if-else 블록이 너무 길어질 수 있습니다 …
@if $hat_type == "red-hat1" {
background: url($red-hat1) no-repeat center;
} @else if $hat_type == "red-hat2" {
background: url($red-hat2) no-repeat center;
} @else if $hat_type == "squirrel2" {
background: url($squirrel2) no-repeat center;
}
scss에서 함수를 사용해 보았습니다.
background: url(get_image($hat_type)) no-repeat center;
@function get_image($name){
@return "assets/decorations/" + $name + ".png"
}
하지만 이 경우 URL이 다음과 같이 생성됩니다.
https://www.domain.com/stylesheets/assets/decorations/squirrel2.png
이것은 작동하지 않으며, 대신 다음과 같이 해석되어야 합니다 …
https://www.domain.com/uploads/db9860/original/3X/9/1/91d36fdb030047c6390f9ca85604fdbfd2e3fc12.png
누군가 힌트를 주실 수 있을까요? 정말 감사합니다 ![]()


