With the %()
function, you can format strings in Less. This function is very similar to the printf
function found in other programming languages.
For this recipe, you will only need a Less compiler. You can use the command line lessc
or the client-side less.js
compiler and inspect the results in your browser. We have covered the installation part of these compilers in Chapter 1, Getting to Grips with the Basics of Less.
To find out how to use the
%()
function, you can compile the following Less code and inspect the compiled CSS code:formattedstrings { quotesincluded: %("Open the %a file","../less.txt"); quotesincludedescaped: %("Open the %A file","../less.txt"); quotesremoved: %("Open the %s file","../less.txt"); quotesremovedescaped: %("Open the %S file","../less.txt"); }
After compiling the preceding Less code, your compiled CSS code will look like the following:
formattedstrings { quotesincluded: "Open the "../less.txt" file"; quotesincludedescaped...