Writerside Help

Variables

Variables are named values with a unique name and may be used in various places across the documentation.

So when you change its value, it will change across all documents.

Things are often subject to change and worth putting into a variable:

  • versions;

  • a product or a company name;

  • company's contact data: email or phone number;

  • a link to the support service.

Declare a variable

Variables have scopes, and they can be global and local.

Global variable exists within a module, while local – within a topic or a snippet.

  • To create a global variable, declare it in the v.list file in the module directory and specify name, type, and value.

    <vars> <var name="latest_version" instance="web" value="1.8" type="string" /> </vars>
  • To create a local variable, declare it in a topic file or in a snippet.

    <snippet id="tip_general"> <var name="latest" value="1.8"/>
    <var name="latest" value="1.8"/> > We recommend switching to the version %latest%. > {style="note"}

Use a variable

  • Use the variable declared previously:

    <note> <p>We recommend switching to the version %latest%.</p> </note>
    > We recommend switching to the version %latest%. > {style="note"}
  • Overwrite the variable in a certain element, for example, a paragraph, by declaring it one more time with other value.

    <var name="var" value="The original value"/> <p>%var%</p> <p> <var name="var" value="The new value"/> %var% </p>
    <var name="var" value="original value"/> Paragraph 1 and some text and some %var%. <-- Some other Markdown contents --> <var name="var" value="new value"/> Paragraph 2 and some text and some %var%.
    <var name="var" value="The original value"/> <p>%var%</p> <p> <var name="var" value="The new value"/> %var% </p>
    <var name="var" value="original value"/> Paragraph 1 with some text and some %var%. <-- Some other Markdown contents --> <var name="var" value="new value"/> Paragraph 2 with some text and some %var%.

Refer to an instance name

  • Use the instance variable to refer to an instance name.

    <chapter title="Chapter title"> <p>When you click this button, %instance% automatically converts values.</p>
    ## Chapter title When you click this button, %instance% automatically converts values.
    <chapter title="Chapter title"> <p>When you click this button, %instance% automatically converts values.</p>
    ## Chapter title When you click this button, %instance% automatically converts values.

Ignore a variable

  • If you have %-enclosed text in the content, for example, in links or code blocks, you can either escape it by adding \ after the first % symbol or use ignore-vars="true".

    The setting will apply to all child elements and the content inside the tag.

Last modified: 16 July 2024