Book Image

LESS WEB DEVELOPMENT COOKBOOK

Book Image

LESS WEB DEVELOPMENT COOKBOOK

Overview of this book

Table of Contents (19 chapters)
Less Web Development Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Formatting strings


With the %() function, you can format strings in Less. This function is very similar to the printf function found in other programming languages.

Getting ready

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.

How to do it…

  1. 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");
    }
  2. After compiling the preceding Less code, your compiled CSS code will look like the following:

    formattedstrings {
      quotesincluded: "Open the "../less.txt" file";
      quotesincludedescaped...