パックの構造/適用方法によっては、ループを使用して一連の一般的なスタイルを生成できる場合があります。こちらのドキュメントをご覧ください:http ://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#id35
画像のURLを取得するために本当に3つの別々のコンポーネントが必要ですか?そうではないでしょう:$img
そしてそれを/folder/img.ext
はるかに簡単に設定しますか?
#{}
また、ちなみにリピートは必要ありません。
これがあなたが求めているものであることを願っています…質問は、あなたが実際に何をする必要があるかという点であまり具体的ではありません。
乾杯、ジャニス
アップデート:
さて、あなたはあなたの質問を更新したようです(ありがとう)。私はこれが一般的な使用のために少し良いかもしれないと信じています:
@mixin background($imgpath,$position:0 0,$repeat: no-repeat) {
background: {
image: url($imgpath);
position: $position;
repeat: $repeat;
}
}
.testing {
@include background('/my/img/path.png');
}
これにより、次のように出力されます。
.testing {
background-image: url("/my/img/path.png");
background-position: 0 0;
background-repeat: no-repeat;
}
または、短縮バージョンを使用できます。
@mixin backgroundShorthand($imgpath,$position:0 0,$repeat: no-repeat) {
background: transparent url(#{$imgpath}) $repeat $position;
}
.testing2 {
@include backgroundShorthand('/my/img/path.png');
}
生成されるもの:
.testing2 {
background: transparent url(/my/img/path.png) no-repeat 0 0;
}
最後に、イメージディレクトリへのベースパスを個別に指定する場合は、次の操作を実行できます。
$imagedir:'/static/images/'; // define the base path before the mixin
@mixin backgroundShorthandWithExternalVar($filename,$position:0 0,$repeat: no-repeat) {
background: transparent url(#{$imagedir}#{$filename}) $repeat $position;
}
.testing3 {
@include backgroundShorthandWithExternalVar('filename.png');
}
これにより、以下が生成されます。
.testing3 {
background: transparent url(/static/images/filename.png) no-repeat 0 0;
}
これはあなたが必要としたものですか?
そうでない場合は、質問または返信/コメントを更新してください。