<?xml version="1.0" encoding="UTF-8"?>
<helpdocument version="1.0">
<!--
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->

<meta>
  <topic id="textswriterguideconditional_textxml" indexer="include" status="PUBLISH">
    <title id="tit" xml-lang="en-US">Conditional Text</title>
    <filename>/text/swriter/guide/conditional_text.xhp</filename>
  </topic>
</meta>

<body>

<bookmark xml-lang="en-US" branch="index" id="bm_id3155619">
  <bookmark_value>matching conditional text in fields</bookmark_value>
  <bookmark_value>if-then queries as fields</bookmark_value>
  <bookmark_value>conditional text; setting up</bookmark_value>
  <bookmark_value>text; conditional text</bookmark_value>
  <bookmark_value>defining;conditions</bookmark_value>
</bookmark>


<paragraph id="hd_id3155619" role="heading" level="1" xml-lang="en-US"><variable id="conditional_text"><link href="text/swriter/guide/conditional_text.xhp" name="Conditional Text">Conditional Text</link></variable></paragraph>
<paragraph id="par_id3155879" role="paragraph" xml-lang="en-US">You can set up fields in your document that display text when a condition that you define is met. For example, you can define the conditional text that is displayed in a series of reminder letters.</paragraph>
<paragraph id="par_id3155895" role="paragraph" xml-lang="en-US">Setting up conditional text in this example is a two-part process. First you create a variable, and then you create the condition.</paragraph>

<paragraph id="hd_id3153175" role="heading" level="2" xml-lang="en-US">To Define a Conditional Variable</paragraph>
<paragraph id="par_id3153185" role="paragraph" xml-lang="en-US">The first part of the example is to define a variable for the condition statement.</paragraph>

<list type="ordered">
  <listitem>
    <paragraph id="par_id3155566" role="listitem" xml-lang="en-US">Choose <item type="menuitem">Insert - Field - More Fields</item>, and then click the <item type="menuitem">Variables</item> tab.</paragraph>
  </listitem>
  <listitem>
    <paragraph id="par_id3147759" role="listitem" xml-lang="en-US">Click "Set variable" in the <item type="menuitem">Type</item> list.</paragraph>
  </listitem>
  <listitem>
    <paragraph id="par_id3147784" role="listitem" xml-lang="en-US">Type a name for the variable in the <item type="menuitem">Name</item> box, for example <item type="literal">Reminder</item>.</paragraph>
  </listitem>
  <listitem>
    <paragraph id="par_id3147810" role="listitem" xml-lang="en-US">Click "Text" in the <item type="menuitem">Format</item> list.</paragraph>
  </listitem>
  <listitem>
    <paragraph id="par_id7748344" role="listitem" xml-lang="en-US">Enter <item type="literal">1</item> in the <item type="menuitem">Value</item> box, and then click <item type="menuitem">Insert</item>.<br/>The Format list now displays a "General" format.</paragraph>
  </listitem>
</list>

<paragraph id="hd_id3145645" role="heading" level="2" xml-lang="en-US">To Define a Condition and the Conditional Text</paragraph>
<paragraph id="par_id3145659" role="paragraph" xml-lang="en-US">The second part of the example is to define the condition that must be met, and to insert a placeholder for displaying the conditional text in your document.</paragraph>

<list type="ordered">
  <listitem>
    <paragraph id="par_id3151193" role="listitem" xml-lang="en-US">Place the cursor where you want to insert the conditional text in your text.</paragraph>
  </listitem>
  <listitem>
    <paragraph id="par_id3151212" role="listitem" xml-lang="en-US">Choose <item type="menuitem">Insert - Field - More Fields</item>, and then click the <item type="menuitem">Functions</item> tab.</paragraph>
  </listitem>
  <listitem>
    <paragraph id="par_id3151250" role="listitem" xml-lang="en-US">Click "Conditional text" in the <item type="menuitem">Type</item> list.</paragraph>
  </listitem>
  <listitem>
    <paragraph id="par_id3155936" role="listitem" xml-lang="en-US">Type <item type="literal">Reminder EQ "3"</item> in the <item type="menuitem">Condition</item> box. In other words, the conditional text will be displayed when the variable in the field that you defined in the first part of this example is equal to three.</paragraph>
    <paragraph id="par_id3155969" role="listitem" xml-lang="en-US">The quotation marks enclosing the "3" indicate that the variable that you defined in the first part of this example is a text string.</paragraph>
  </listitem>
</list>

<list type="ordered" startwith="5">
  <listitem>
    <paragraph id="par_id3150446" role="listitem" xml-lang="en-US">Type the text that you want to display when the condition is met in the <emph>Then</emph> box. There is almost no limit to the length of the text that you can enter. You can paste a paragraph into this box.</paragraph>
  </listitem>
  <listitem>
    <paragraph id="par_id3150473" role="listitem" xml-lang="en-US">Click <emph>Insert</emph>, and then click <emph>Close</emph>.</paragraph>
  </listitem>
</list>

<paragraph id="hd_id3155073" role="heading" level="2" xml-lang="en-US">To Display the Conditional Text</paragraph>
<paragraph id="par_id3155086" role="paragraph" xml-lang="en-US">In this example, the conditional text is displayed when the value of the conditional variable is equal to 3.</paragraph>

<list type="ordered">
  <listitem>
    <paragraph id="par_id3155110" role="listitem" xml-lang="en-US">Place your cursor in front of the field that you defined in the first part of this example, and then choose <emph>Edit - Fields</emph>.</paragraph>
  </listitem>
  <listitem>
    <paragraph id="par_id3155136" role="listitem" xml-lang="en-US">Replace the number in the <item type="menuitem">Value</item> box with 3, and then click <item type="menuitem">Close</item>.</paragraph>
  </listitem>
  <listitem>
    <paragraph id="par_id3155168" role="listitem" xml-lang="en-US">If the field does not automatically update, press F9.</paragraph>
  </listitem>
</list>

<section id="relatedtopics">
<embed href="text/swriter/guide/fields_userdata.xhp#fields_userdata"/>
<embed href="text/swriter/guide/conditional_text2.xhp#conditional_text2"/>
<embed href="text/swriter/01/04090200.xhp#defining_conditions"/>
<paragraph id="par_id3145714" role="paragraph" xml-lang="en-US"><link href="text/swriter/02/14020000.xhp" name="List of conditional operators">List of conditional operators</link></paragraph>
</section>
</body>

</helpdocument>