M
M
myskypesla2016-05-24 10:57:43
JSON
myskypesla, 2016-05-24 10:57:43

How to insert variable from json to sass?

Hi all. Tell me how to insert a variable from JSON into SASS ? Maybe someone has done this?
Such a situation: there is a project structure that assumes that the path to the first picture on the first page will be like this:

background: url(assets/private/common/img/logo.png);

And the path to the second picture of the same page will be like this:
background: url(assets/private/page/img/avatar.png);
.
What you need to do: Register all paths in JSON to certain variables, and register the variable in SASS, it will schematically look like this:
1st picture:
"переменная_№1_из_JSON": "assets/private/common";
background: url("переменная_№1_из_JSON"/img/logo.png);

2nd picture:
"переменная_№2_из_JSON": "assets/private/page";
background: url("переменная_№2_из_JSON"/img/logo.png);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2016-05-24
@sim3x

https://github.com/vigetlabs/sass-json-vars
but I would not advise doing such garbage
js should not know anything about image paths
in css / sass at all there is no need to redefine image paths (maximum - redefine paths during assembly )
*for general development - you can create any garbage, but why
https://css-tricks.com/making-sass-talk-to-javascr...

A
Andrey Prozorov, 2016-10-06
@i_d_1

https://www.npmjs.com/package/gulp-json-css

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question