How to change the value of a dynamic variable

how to use dynamically countless variables. I mean how to dynamically assign a value in a countless file. Is there any way?

The style.less file contains

@url_image: 

#head{ background: url(@url_image) no-repeat left top white;}

How to assign a value at runtime?

+1
source share
3 answers

When you say that you are dynamically changing in a .less file, I'm not sure why you want to just change it in a smaller file. If you simply modify it in a .less file, you will have to compile the file to transfer the changes to the style.min.css and style.css files that you cannot do programmatically.

This is what you can do:

 $('#head').css('background-image', "url("new-source");

So jquery / javascript is your best bet.

0
source

. , . - , , :

var parser = new dotless.Core.Parser.Parser();
var env = new dotless.Core.Parser.Infrastructure.Env { Compress = true, Debug = true, KeepFirstSpecialComment = false, DisableVariableRedefines = false };
var tree = parser.Parse(css.Detail.Text, null);

foreach (var key in layout.LessDetails.CurrentValues.Keys)
{
   var rule = tree.Variable("@" + key, tree);

   if (rule != null)
   {
      string value = layout.LessDetails.CurrentValues[key];

      if (value != null && value.StartsWith("#"))
      {
         rule.Value = new dotless.Core.Parser.Tree.Color(value.TrimStart('#'));
      }
   }
}

css.Detail.GeneratedText = tree.ToCSS(env);

, , . dotless.Core.Parser.Functions .

. css.Detail.Text. , modifyVars less.js. , .

+1

, .

var config = DotlessConfiguration.GetDefaultWeb();
config.DisableVariableRedefines = true;

string less = File.ReadAllText(fileName);
StringBuilder sb = new StringBuilder(less);
sb.AppendLine(string.Format("{0}: {1};", "@url_image", "image.jpg"));

return LessWeb.Parse(sb.ToString(), config);
0

All Articles