Qbs

Blog Documentation Get Qbs Community

texttemplate

Provides support for text template files. More...

Since: Qbs 1.13

Properties

Detailed Description

The texttemplate module provides support for text template files.

Example

Consider the following text file greeting.txt.in.

${greeting} ${name}!

This can be used in a project like this:

Product {
    type: ["text"]
    files: ["greeting.txt.in"]
    Depends { name: "texttemplate" }
    texttemplate.dict: ({
            greeting: "Hello",
            name: "World"
        })
}

Which will create the file greeting.txt.

Hello World!

The same result can be achieved using the alternative placeholder format:

Product {
    type: ["text"]
    files: ["greeting.txt.in"]
    Depends { name: "texttemplate" }
    texttemplate.placeholder: "@@"
    texttemplate.dict: ({
            greeting: "Hello",
            name: "World"
        })
}

Where greeting.txt.in contains:

@greeting@ @name@!

Placeholder Syntax

The texttemplate module supports two placeholder formats, controlled by the placeholder property.

A placeholder ${foo} is replaced by its corresponding value in texttemplate.dict. Placeholder names consist of alphanumeric characters only.

The placeholder ${$} is always replaced with $. If you need a literal ${foo} in your template, use ${$}{foo}.

When texttemplate.placeholder is set to "@@", placeholders use the format @foo@ instead.

Placeholders that are not defined in the dictionary will produce an error.

Relevant File Tags

TagAuto-tagged File NamesSinceDescription
"texttemplate.input"*.in1.13.0Source files with this tag serve as inputs for the text template rule.

Property Documentation

dict : var

The dictionary containing values for all keys used in the template file.

Default: {}

outputFileName : string

The output file name that is assigned to produced artifacts.

Default: Complete base name of the input file

outputTag : string

The output tag that is assigned to produced artifacts.

Default: "text"

placeholder : string [since Qbs 3.1]

The placeholder format to use for text template files.

Possible values: "${}", "@@"

Default: "${}"

This property was introduced in Qbs 3.1.