<!--
	This source file is part of the open source project
	ExpressionEngine User Guide (https://github.com/ExpressionEngine/ExpressionEngine-User-Guide)

	@link      https://expressionengine.com/
	@copyright Copyright (c) 2003-2021, Packet Tide, LLC. (https://packettide.com)
	@license   https://expressionengine.com/license Licensed under Apache License, Version 2.0
-->
<!DOCTYPE html>
<html lang="en" dir="ltr">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">

		<title>Conditional Tags — ExpressionEngine 5.4.2 Documentation</title>

		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css" />

		<link rel="stylesheet" href="../_assets/default.min.css?v=3">

		<!-- Favicons -->
		<link rel="apple-touch-icon" sizes="180x180" href="../_assets/images/favicons/apple-touch-icon.png">
		<link rel="icon" type="image/png" sizes="32x32" href="../_assets/images/favicons/favicon-32x32.png">
		<link rel="icon" type="image/png" sizes="16x16" href="../_assets/images/favicons/favicon-16x16.png">
		<link rel="manifest" href="../_assets/images/favicons/site.webmanifest">
		<link rel="mask-icon" href="../_assets/images/favicons/safari-pinned-tab.svg" color="#2e6abd">
		<link rel="shortcut icon" href="../_assets/images/favicons/favicon.ico">
		<meta name="msapplication-TileColor" content="#2e6abd">
		<meta name="msapplication-config" content="../_assets/images/favicons/browserconfig.xml">
		<meta name="theme-color" content="#ffffff">

		<style>.sidebar-toc { visibility: hidden; }</style>
		<noscript><style>.sidebar-toc { visibility: visible; }</style></noscript>
	</head>
	<body>

		<div class="header">
			<div class="header-content">
				<a href="https://docs.expressionengine.com/latest" class="header-logo"><img src="../_assets/images/ee-logo-white.svg" alt=""></a>
				<a href="https://docs.expressionengine.com/latest" class="header-title">ExpressionEngine Docs</a>

				<nav>
					<a href="https://u.expressionengine.com" class="hide font-monospace">{ee:u}</a>
					<a href="https://expressionengine.com/forums" class="hide">Forums</a>

					<div class="version-button-wrapper">
					<div class="dropdown">
							<a class="" href="#">v5<span class="i-arrow-down"></span></a>
							<div class="dropdown-menu">
								<div class="dropdown-menu-inner">
									<a href="https://docs.expressionengine.com/latest/">v6</a>
									<a class="active" href="https://docs.expressionengine.com/v5/">v5</a>
									<a href="https://docs.expressionengine.com/v4/">v4</a>
									<a href="https://docs.expressionengine.com/v3/">v3</a>
									<a href="https://docs.expressionengine.com/v2/">v2</a>
									<a href="https://docs.expressionengine.com/v1/">v1</a>
								</div>
							</div>
						</div>
						<a href="https://docs.expressionengine.com/downloads/v5" class="download-button"><img src="../_assets/images/download.svg" alt=""></a>
					</div>
				</nav>

				<div class="hamburger mobile-menu-button" onclick="toggleMobileMenu();">
					<span></span><span></span><span></span>
				</div>
			</div>
		</div>

		<div class="sidebar-container">
			<div class="sidebar">
				<div class="sidebar-search">
				<input type="text" class="search-input" id="docsearch-input" name="search" placeholder="Search">
					<!-- <div class="sidebar-sponsor">
						<p>Sponsored By:</p><img src="" alt="">
					</div> -->
				</div>

				<div class="sidebar-toc">
					<ul><li  class=""><a href="../index.html">Welcome</a></li><li  class=""><a >Installation & Updates</a><ul><li  class=""><a href="../installation/requirements.html">System Requirements</a></li><li  class=""><a href="../installation/installation.html">Installation</a></li><li  class=""><a href="../installation/best-practices.html">Best Practices</a></li><li  class=""><a href="../installation/updating.html">Updating</a></li><li  class=""><a href="../installation/changelog.html">Change Log</a></li></ul></li><li  class=""><a >Getting Started</a><ul><li  class=""><a href="../getting-started/the-big-picture.html">The Big Picture</a></li><li  class=""><a href="../getting-started/ten-minute-primer.html">10 Minute Primer</a></li></ul></li><li  class=""><a >General Information</a><ul><li  class=""><a href="../general/url-structure.html">URL Structure</a></li><li  class=""><a href="../general/404pages.html">404 Pages</a></li><li  class=""><a href="../general/database-backup.html">Backing Up Your Site</a></li><li  class=""><a href="../general/moving.html">Moving to Another Server</a></li><li  class=""><a href="../general/gdpr.html">GDPR Compliance</a></li><li  class=""><a href="../general/cookies.html">Cookies</a></li><li  class=""><a href="../general/date-localization.html">Date Localization</a></li><li  class=""><a href="../general/languages.html">Language Packs</a></li><li  class=""><a href="../general/system-configuration-overrides.html">System Config Overrides</a></li><li  class=""><a href="../general/text-formatting.html">Text Formatting</a></li><li  class=""><a href="../general/converting-to-innodb.html">Converting to InnoDB</a></li><li  class=""><a href="../general/bbcode.html">BBCode Reference</a></li><li  class=""><a href="../general/reserved-words.html">Reserved Words</a></li><li  class=""><a href="../general/member-import-xml-format.html">Member XML Format</a></li></ul></li><li  class="active"><a >Templates</a><ul><li  class=""><a href="../templates/overview.html">Overview</a></li><li  class=""><a href="../templates/language.html">Template Language</a></li><li data-active-page="true" class="active"><a href="../templates/conditionals.html">Conditional Tags</a></li><li  class=""><a href="../templates/embedding.html">Embedding Templates</a></li><li  class=""><a href="../templates/layouts.html">Template Layouts</a></li><li  class=""><a href="../templates/partials.html">Template Partials</a></li><li  class=""><a href="../templates/variable.html">Template Variables</a></li><li  class=""><a >Global Template Variables</a><ul><li  class=""><a href="../templates/globals/single-variables.html">Single Global Variables</a></li><li  class=""><a href="../templates/globals/stylesheet.html">Linking to Stylesheets</a></li><li  class=""><a href="../templates/globals/url-segments.html">URL Segment Variables</a></li><li  class=""><a href="../templates/globals/consent.html">Consent Variables</a></li><li  class=""><a href="../templates/globals/path.html">Path Variables</a></li><li  class=""><a href="../templates/globals/preload-replacement.html">Preload Text Replacements</a></li></ul></li><li  class=""><a href="../templates/variable-modifiers.html">Variable Modifiers</a></li><li  class=""><a href="../templates/date-variable-formatting.html">Date Variable Formatting</a></li><li  class=""><a href="../templates/routes.html">Template Routes</a></li><li  class=""><a href="../templates/pagination.html">Pagination</a></li><li  class=""><a href="../templates/engine.html">The Template Engine</a></li></ul></li><li  class=""><a >Channels</a><ul><li  class=""><a href="../channels/entries.html">Entries Tag</a></li><li  class=""><a href="../channels/info.html">Channel Information Tag</a></li><li  class=""><a href="../channels/entry-linking.html">Next/Previous Entries</a></li><li  class=""><a href="../channels/entry-spanning.html">Spanning Across Pages</a></li><li  class=""><a href="../channels/entry-tracking.html">Entry Views Tracking</a></li><li  class=""><a href="../channels/dynamic-parameters.html">Dynamic Parameters</a></li><li  class=""><a href="../channels/categories.html">Categories Tag</a></li><li  class=""><a href="../channels/category-archive.html">Category Archive Tag</a></li><li  class=""><a href="../channels/category-heading.html">Category Heading Tag</a></li><li  class=""><a href="../channels/archive-months.html">Archive Month Links</a></li><li  class=""><a href="../channels/sets.html">Channel Sets</a></li><li  class=""><a href="../channels/calendar.html">Calendar Tag</a></li><li  class=""><a >Channel Form</a><ul><li  class=""><a href="../channels/channel-form/overview.html">Channel Form Tag</a></li><li  class=""><a href="../channels/channel-form/examples.html">Examples</a></li><li  class=""><a href="../channels/channel-form/inputs.html">Form Inputs</a></li><li  class=""><a href="../channels/channel-form/fields.html">Other Fields</a></li><li  class=""><a href="../channels/channel-form/status.html">Status Selection</a></li><li  class=""><a href="../channels/channel-form/categories.html">Category Selection</a></li><li  class=""><a href="../channels/channel-form/development.html">Development</a></li></ul></li></ul></li><li  class=""><a >Comments</a><ul><li  class=""><a href="../comment/overview.html">Overview</a></li><li  class=""><a href="../comment/entries.html">Entries Tag</a></li><li  class=""><a href="../comment/form.html">Submission Form</a></li><li  class=""><a href="../comment/subscriptions.html">Subscriptions</a></li><li  class=""><a href="../comment/control-panel.html">Control Panel</a></li></ul></li><li  class=""><a >Add-Ons</a><ul><li  class=""><a href="../add-ons/overview.html">Overview</a></li><li  class=""><a href="../add-ons/blacklist.html">Blacklist / White List</a></li><li  class=""><a href="../add-ons/consent.html">Consent</a></li><li  class=""><a href="../add-ons/email.html">Email</a></li><li  class=""><a href="../add-ons/emoji.html">Emoji</a></li><li  class=""><a href="../add-ons/file.html">File</a></li><li  class=""><a >Discussion Forum</a><ul><li  class=""><a href="../add-ons/forum/index.html">Overview</a></li><li  class=""><a href="../add-ons/forum/setup.html">Setup</a></li><li  class=""><a href="../add-ons/forum/boards.html">Boards</a></li><li  class=""><a href="../add-ons/forum/themes.html">Themes</a></li><li  class=""><a href="../add-ons/forum/global-variables.html">Global Variables</a></li><li  class=""><a href="../add-ons/forum/user-management.html">User Management</a></li><li  class=""><a href="../add-ons/forum/channel-forum.html">Associating Channel Entries with Forum Topics</a></li><li  class=""><a href="../add-ons/forum/recent-topics.html">Recent Forum Topics</a></li><li  class=""><a href="../add-ons/forum/signatures.html">Signatures and Avatars</a></li><li  class=""><a href="../add-ons/forum/helper.html">Helper</a></li><li  class=""><a href="../add-ons/forum/other-features.html">Other Features</a></li></ul></li><li  class=""><a href="../add-ons/http-header.html">HTTP Header</a></li><li  class=""><a href="../add-ons/ip-to-nation.html">IP to Nation</a></li><li  class=""><a href="../add-ons/metaweblog-api.html">Metaweblog API</a></li><li  class=""><a href="../add-ons/moblog.html">Moblog</a></li><li  class=""><a href="../add-ons/pages.html">Pages</a></li><li  class=""><a href="../add-ons/query.html">Query</a></li><li  class=""><a href="../add-ons/rss.html">RSS</a></li><li  class=""><a href="../add-ons/rss-parser.html">RSS Parser</a></li><li  class=""><a href="../add-ons/rte.html">Rich Text Editor</a></li><li  class=""><a >Search</a><ul><li  class=""><a href="../add-ons/search/index.html">Overview</a></li><li  class=""><a href="../add-ons/search/simple.html">Simple Form Tag</a></li><li  class=""><a href="../add-ons/search/advanced.html">Advanced Form Tag</a></li><li  class=""><a href="../add-ons/search/results.html">Displaying Results</a></li></ul></li><li  class=""><a >Simple Commerce</a><ul><li  class=""><a href="../add-ons/simple-commerce/index.html">Overview</a></li><li  class=""><a href="../add-ons/simple-commerce/control-panel.html">Control Panel</a></li><li  class=""><a href="../add-ons/simple-commerce/email-templates.html">Email Templates</a></li><li  class=""><a href="../add-ons/simple-commerce/ipn.html">Instant Payment Notification</a></li><li  class=""><a href="../add-ons/simple-commerce/items.html">Managing Store Items</a></li><li  class=""><a href="../add-ons/simple-commerce/paypal-settings.html">PayPal Settings</a></li><li  class=""><a href="../add-ons/simple-commerce/purchases.html">Managing Store Purchases</a></li></ul></li><li  class=""><a href="../add-ons/spam.html">Spam</a></li><li  class=""><a href="../add-ons/statistics.html">Statistics</a></li><li  class=""><a href="../add-ons/emoticon.html">Emoticon (Deprecated)</a></li></ul></li><li  class=""><a >Fieldtypes</a><ul><li  class=""><a href="../fieldtypes/overview.html">Overview</a></li><li  class=""><a href="../fieldtypes/date.html">Date</a></li><li  class=""><a href="../fieldtypes/duration.html">Duration</a></li><li  class=""><a href="../fieldtypes/email-address.html">Email Address</a></li><li  class=""><a href="../fieldtypes/file.html">File</a></li><li  class=""><a href="../fieldtypes/file-grid.html">File Grid</a></li><li  class=""><a href="../fieldtypes/fluid.html">Fluid</a></li><li  class=""><a href="../fieldtypes/grid.html">Grid</a></li><li  class=""><a href="../fieldtypes/relationships.html">Relationships</a></li><li  class=""><a href="../fieldtypes/rte.html">Rich Text Editor</a></li><li  class=""><a href="../fieldtypes/select.html">Checkboxes, Radio Buttons, Select, Multiselect</a></li><li  class=""><a href="../fieldtypes/text.html">Text Input</a></li><li  class=""><a href="../fieldtypes/textarea.html">Textarea</a></li><li  class=""><a href="../fieldtypes/toggle.html">Toggle</a></li><li  class=""><a href="../fieldtypes/url.html">URL</a></li></ul></li><li  class=""><a href="../member/index.html">Member Management</a></li><li  class=""><a >Control Panel</a><ul><li  class=""><a href="../control-panel/index.html">The Control Panel</a></li><li  class=""><a href="../control-panel/overview.html">CP Overview</a></li><li  class=""><a href="../control-panel/create.html">Create</a></li><li  class=""><a href="../control-panel/channels.html">Channels</a></li><li  class=""><a href="../control-panel/entry-manager.html">Entry Manager</a></li><li  class=""><a href="../control-panel/file-manager.html">File Manager</a></li><li  class=""><a href="../control-panel/field-manager.html">Field Manager</a></li><li  class=""><a href="../control-panel/member-manager.html">Member Manager</a></li><li  class=""><a href="../control-panel/member-profile.html">Member Profile</a></li><li  class=""><a href="../control-panel/template-manager.html">Template Manager</a></li><li  class=""><a href="../control-panel/addons-manager.html">Add-On Manager</a></li><li  class=""><a href="../control-panel/categories.html">Categories</a></li><li  class=""><a href="../control-panel/utilities.html">Utilities</a></li><li  class=""><a href="../control-panel/system-logs.html">System Logs</a></li><li  class=""><a >System Settings</a><ul><li  class=""><a href="../control-panel/settings/index.html">Overview</a></li><li  class=""><a href="../control-panel/settings/general.html">General Settings</a></li><li  class=""><a href="../control-panel/settings/avatars.html">Avatar</a></li><li  class=""><a href="../control-panel/settings/captcha.html">CAPTCHA</a></li><li  class=""><a href="../control-panel/settings/comments.html">Comment</a></li><li  class=""><a href="../control-panel/settings/content-design.html">Content & Design</a></li><li  class=""><a href="../control-panel/settings/consents.html">Consents</a></li><li  class=""><a href="../control-panel/settings/debug-output.html">Debugging & Output</a></li><li  class=""><a href="../control-panel/settings/email.html">Outgoing Email</a></li><li  class=""><a href="../control-panel/settings/hit-tracking.html">Hit Tracking</a></li><li  class=""><a href="../control-panel/settings/members.html">Member</a></li><li  class=""><a href="../control-panel/settings/messages.html">Messaging</a></li><li  class=""><a href="../control-panel/settings/security-privacy.html">Security & Privacy</a></li><li  class=""><a href="../control-panel/settings/template.html">Template</a></li><li  class=""><a href="../control-panel/settings/throttling.html">Access Throttling</a></li><li  class=""><a href="../control-panel/settings/urls.html">URL and Path</a></li><li  class=""><a href="../control-panel/settings/word-censor.html">Word Censorship</a></li><li  class=""><a href="../control-panel/settings/html-buttons.html">HTML Buttons</a></li><li  class=""><a href="../control-panel/settings/menu-manager.html">Menu Manager</a></li></ul></li><li  class=""><a href="../control-panel/footer.html">CP Footer</a></li></ul></li><li  class=""><a >Security</a><ul><li  class=""><a href="../security/general-tips.html">Tips</a></li><li  class=""><a href="../security/captchas.html">Captchas</a></li><li  class=""><a href="../security/spam-protection.html">Spam Protection</a></li></ul></li><li  class=""><a >Optimization</a><ul><li  class=""><a href="../optimization/caching.html">Caching and Performance</a></li><li  class=""><a href="../optimization/handling-extreme-traffic.html">Handling Extreme Traffic</a></li><li  class=""><a href="../optimization/throttling.html">Throttling</a></li><li  class=""><a href="../optimization/new-relic.html">New Relic Performance Monitoring</a></li></ul></li><li  class=""><a >Multiple Sites</a><ul><li  class=""><a href="../msm/overview.html">Overview</a></li><li  class=""><a href="../msm/code.html">Variables and Parameter</a></li></ul></li><li  class=""><a >Troubleshooting</a><ul><li  class=""><a href="../troubleshooting/general.html">General</a></li><li  class=""><a href="../troubleshooting/installation.html">Installation</a></li><li  class=""><a href="../troubleshooting/templates.html">Templates</a></li><li  class=""><a href="../troubleshooting/control-panel.html">Control Panel</a></li><li  class=""><a href="../troubleshooting/channels-and-entries.html">Channels and Entries</a></li><li  class=""><a href="../troubleshooting/email.html">Email</a></li><li  class=""><a href="../troubleshooting/simple-commerce-module.html">Simple Commerce Module</a></li><li  class=""><a href="../troubleshooting/error-messages.html">Error Messages</a></li></ul></li><li  class=""><a >Add-On Development</a><ul><li  class=""><a href="../development/addon-setup-php-file.html">The addon.setup.php File</a></li><li  class=""><a href="../development/plugins.html">Plugins</a></li><li  class=""><a href="../development/modules.html">Modules</a></li><li  class=""><a href="../development/extensions.html">Extensions</a></li><li  class=""><a >Extension Hooks</a><ul><li  class=""><a >Global</a><ul><li  class=""><a href="../development/extension-hooks/global/core.html">Core Library</a></li><li  class=""><a href="../development/extension-hooks/global/email.html">Email Library</a></li><li  class=""><a href="../development/extension-hooks/global/filemanager.html">Filemanager Library</a></li><li  class=""><a href="../development/extension-hooks/global/functions.html">Functions Library</a></li><li  class=""><a href="../development/extension-hooks/global/grid.html">Grid Fieldtype</a></li><li  class=""><a href="../development/extension-hooks/global/input.html">Input Library</a></li><li  class=""><a href="../development/extension-hooks/global/member-model.html">Legacy Member Model</a></li><li  class=""><a href="../development/extension-hooks/global/output.html">Output Library</a></li><li  class=""><a href="../development/extension-hooks/global/pagination.html">Pagination Library</a></li><li  class=""><a href="../development/extension-hooks/global/relationships.html">Relationships Fieldtype</a></li><li  class=""><a href="../development/extension-hooks/global/session.html">Session Library</a></li><li  class=""><a href="../development/extension-hooks/global/template.html">Template Library</a></li><li  class=""><a href="../development/extension-hooks/global/text-helper.html">Text Helper</a></li><li  class=""><a href="../development/extension-hooks/global/typography.html">Typography Library</a></li></ul></li><li  class=""><a >API Libraries</a><ul><li  class=""><a href="../development/extension-hooks/api/channel-fields.html">Channel Fields API</a></li><li  class=""><a href="../development/extension-hooks/api/template-structure.html">Template Structure API</a></li></ul></li><li  class=""><a >Control Panel</a><ul><li  class=""><a href="../development/extension-hooks/cp/admin-content.html">Admin Content Controller</a></li><li  class=""><a href="../development/extension-hooks/cp/css.html">CSS Controller</a></li><li  class=""><a href="../development/extension-hooks/cp/design.html">Design Controller</a></li><li  class=""><a href="../development/extension-hooks/cp/javascript.html">Javascript Controller</a></li><li  class=""><a href="../development/extension-hooks/cp/login.html">Login Controller</a></li><li  class=""><a href="../development/extension-hooks/cp/members.html">Members Controller</a></li><li  class=""><a href="../development/extension-hooks/cp/menu.html">Control Panel Menu</a></li><li  class=""><a href="../development/extension-hooks/cp/myaccount.html">My Account Controller</a></li><li  class=""><a href="../development/extension-hooks/cp/publish.html">Publish Controller</a></li></ul></li><li  class=""><a >Models</a><ul><li  class=""><a href="../development/extension-hooks/model/category-field.html">CategoryField Model</a></li><li  class=""><a href="../development/extension-hooks/model/category-group.html">CategoryGroup Model</a></li><li  class=""><a href="../development/extension-hooks/model/category.html">Category Model</a></li><li  class=""><a href="../development/extension-hooks/model/channel.html">Channel Model</a></li><li  class=""><a href="../development/extension-hooks/model/channel-entry.html">Channel Entry Model</a></li><li  class=""><a href="../development/extension-hooks/model/channel-field-group.html">ChannelFieldGroup Model</a></li><li  class=""><a href="../development/extension-hooks/model/channel-field.html">ChannelField Model</a></li><li  class=""><a href="../development/extension-hooks/model/channel-form-settings.html">ChannelFormSettings Model</a></li><li  class=""><a href="../development/extension-hooks/model/channel-layout.html">ChannelLayout Model</a></li><li  class=""><a href="../development/extension-hooks/model/comment.html">Comment Model</a></li><li  class=""><a href="../development/extension-hooks/model/file.html">File Model</a></li><li  class=""><a href="../development/extension-hooks/model/template-global-variable.html">GlobalVariable Model</a></li><li  class=""><a href="../development/extension-hooks/model/member-field.html">MemberField Model</a></li><li  class=""><a href="../development/extension-hooks/model/member-group.html">MemberGroup Model</a></li><li  class=""><a href="../development/extension-hooks/model/member.html">Member Model</a></li><li  class=""><a href="../development/extension-hooks/model/site.html">Site Model</a></li><li  class=""><a href="../development/extension-hooks/model/template-snippet.html">Snippet Model</a></li><li  class=""><a href="../development/extension-hooks/model/template-specialty-template.html">SpecialityTemplate Model</a></li><li  class=""><a href="../development/extension-hooks/model/status.html">Status Model</a></li><li  class=""><a href="../development/extension-hooks/model/template-group.html">TemplateGroup Model</a></li><li  class=""><a href="../development/extension-hooks/model/template-route.html">TemplateRoute Model</a></li><li  class=""><a href="../development/extension-hooks/model/template.html">Template Model</a></li></ul></li><li  class=""><a >Modules</a><ul><li  class=""><a href="../development/extension-hooks/module/channel.html">Channel Module</a></li><li  class=""><a href="../development/extension-hooks/module/channel-form.html">Channel Form</a></li><li  class=""><a href="../development/extension-hooks/module/comment.html">Comment Module</a></li><li  class=""><a href="../development/extension-hooks/module/email.html">Email Module</a></li><li  class=""><a href="../development/extension-hooks/module/forum.html">Forum Module</a></li><li  class=""><a href="../development/extension-hooks/module/member.html">Member Module</a></li><li  class=""><a href="../development/extension-hooks/module/member-auth.html">Member Module Authorization</a></li><li  class=""><a href="../development/extension-hooks/module/member-register.html">Member Module Registration</a></li><li  class=""><a href="../development/extension-hooks/module/member-settings.html">Member Module Settings</a></li><li  class=""><a href="../development/extension-hooks/module/search.html">Search Module</a></li><li  class=""><a href="../development/extension-hooks/module/simple-commerce.html">Simple Commerce Module</a></li><li  class=""><a href="../development/extension-hooks/module/wiki.html">Wiki Module</a></li></ul></li></ul></li><li  class=""><a href="../development/fieldtypes.html">Fieldtypes</a></li><li  class=""><a href="../development/architecture.html">Architecture</a></li><li  class=""><a >Services</a><ul><li  class=""><a href="../development/services/addon.html">Addon Service</a></li><li  class=""><a href="../development/services/alert.html">CP/Alert Service</a></li><li  class=""><a href="../development/services/config.html">Config Service</a></li><li  class=""><a href="../development/services/consent.html">Consent Service</a></li><li  class=""><a href="../development/services/cookie.html">Cookie</a></li><li  class=""><a href="../development/services/csv.html">CSV Library</a></li><li  class=""><a href="../development/services/encrypt.html">Encrypt Service</a></li><li  class=""><a href="../development/services/event.html">Event Service</a></li><li  class=""><a href="../development/services/filepicker.html">CP/FilePicker Service</a></li><li  class=""><a href="../development/services/filter.html">CP/Filter Service</a></li><li  class=""><a >Format Service</a><ul><li  class=""><a href="../development/services/format.html">Format</a></li><li  class=""><a href="../development/services/format/number.html">Number Formatter</a></li><li  class=""><a href="../development/services/format/text.html">Text Formatter</a></li></ul></li><li  class=""><a href="../development/services/ipaddress.html">IP Address Service</a></li><li  class=""><a href="../development/services/live-preview.html">LivePreview Service</a></li><li  class=""><a href="../development/services/memory.html">Memory Service</a></li><li  class=""><a href="../development/services/modal.html">CP/Modal Service</a></li><li  class=""><a >Model Service</a><ul><li  class=""><a href="../development/services/model.html">Model</a></li><li  class=""><a href="../development/services/model/fetching.html">Fetching Models</a></li><li  class=""><a href="../development/services/model/relationships.html">Relationships</a></li><li  class=""><a href="../development/services/model/collection.html">Collections</a></li><li  class=""><a href="../development/services/model/building-your-own.html">Building your own Models</a></li><li  class=""><a href="../development/services/model/relating-models.html">Relating Models</a></li></ul></li><li  class=""><a href="../development/services/pagination.html">CP/Pagination Service</a></li><li  class=""><a href="../development/services/permission.html">Permission Service</a></li><li  class=""><a href="../development/services/sidebar.html">CP/Sidebar Service</a></li><li  class=""><a href="../development/services/spam.html">Spam Service</a></li><li  class=""><a href="../development/services/table.html">CP/Table Service</a></li><li  class=""><a href="../development/services/url.html">CP/URL Service</a></li><li  class=""><a href="../development/services/validation.html">Validation Service</a></li><li  class=""><a href="../development/services/view.html">View Service</a></li></ul></li><li  class=""><a href="../development/tree-datastructure.html">Tree Datastructure</a></li><li  class=""><a href="../development/shared-form-view.html">Shared Form View</a></li><li  class=""><a href="../development/rte-tools.html">RTE Tools API</a></li><li  class=""><a >Control Panel Javascript</a><ul><li  class=""><a href="../development/control-panel-js/events.html">Custom jQuery Events</a></li><li  class=""><a href="../development/control-panel-js/table.html">Table Plugin</a></li><li  class=""><a href="../development/control-panel-js/rich-text-editor.html">Rich Text Editor</a></li><li  class=""><a href="../development/control-panel-js/rangesandselections.html">Ranges and Selections</a></li><li  class=""><a href="../development/control-panel-js/wysihat-api.html">WysiHat API</a></li></ul></li><li  class=""><a href="../development/constants.html">Constants Reference</a></li><li  class=""><a href="../development/json-version-feed.html">JSON Version Feed</a></li><li  class=""><a >Legacy Reference</a><ul><li  class=""><a href="../development/legacy/common-functions.html">Common Functions</a></li><li  class=""><a href="../development/legacy/controllers.html">Controllers</a></li><li  class=""><a href="../development/legacy/drivers.html">Drivers</a></li><li  class=""><a href="../development/legacy/libraries/index.html">Libraries</a><ul><li  class=""><a href="../development/legacy/libraries/creating-libraries.html">Creating Libraries</a></li><li  class=""><a href="../development/legacy/libraries/benchmark.html">Benchmarking Class</a></li><li  class=""><a href="../development/legacy/libraries/cache.html">Cache Class</a></li><li  class=""><a href="../development/legacy/libraries/config.html">Config Class</a></li><li  class=""><a href="../development/legacy/libraries/cp.html">CP Class</a></li><li  class=""><a href="../development/legacy/libraries/database.html">Database Class</a></li><li  class=""><a href="../development/legacy/libraries/email.html">Email Class</a></li><li  class=""><a href="../development/legacy/libraries/file-uploading.html">File Uploading Class</a></li><li  class=""><a href="../development/legacy/libraries/form-validation.html">Form Validation Class</a></li><li  class=""><a href="../development/legacy/libraries/functions.html">Functions Class</a></li><li  class=""><a href="../development/legacy/libraries/image-lib.html">Image Manipulation Class</a></li><li  class=""><a href="../development/legacy/libraries/input.html">Input Class</a></li><li  class=""><a href="../development/legacy/libraries/javascript.html">Javascript Class</a></li><li  class=""><a href="../development/legacy/libraries/language.html">Language Class</a></li><li  class=""><a href="../development/legacy/libraries/layout.html">Layout Class</a></li><li  class=""><a href="../development/legacy/libraries/loader.html">Loader Class</a></li><li  class=""><a href="../development/legacy/libraries/localization.html">Localize Class</a></li><li  class=""><a href="../development/legacy/libraries/logger.html">Logger Class</a></li><li  class=""><a href="../development/legacy/libraries/mime-type.html">Mime Type Class</a></li><li  class=""><a href="../development/legacy/libraries/output.html">Output Class</a></li><li  class=""><a href="../development/legacy/libraries/pagination.html">Pagination Class</a></li><li  class=""><a href="../development/legacy/libraries/rss-parser.html">RSS Parser Class</a></li><li  class=""><a href="../development/legacy/libraries/security.html">Security Class</a></li><li  class=""><a href="../development/legacy/libraries/session.html">Session Class</a></li><li  class=""><a href="../development/legacy/libraries/table.html">Table Class</a></li><li  class=""><a href="../development/legacy/libraries/template.html">Template Class</a></li><li  class=""><a href="../development/legacy/libraries/typography.html">Typography Class</a></li><li  class=""><a href="../development/legacy/libraries/uri.html">URI Class</a></li><li  class=""><a href="../development/legacy/libraries/xmlparser.html">XML Parser Class</a></li></ul></li><li  class=""><a href="../development/legacy/database/index.html">Database Driver</a><ul><li  class=""><a href="../development/legacy/database/active-record.html">Active Record</a></li><li  class=""><a href="../development/legacy/database/results.html">Query Results</a></li><li  class=""><a href="../development/legacy/database/raw.html">Raw Queries and Metadata</a></li><li  class=""><a href="../development/legacy/database/utilities.html">Database Utility Class</a></li><li  class=""><a href="../development/legacy/database/forge.html">Database Forge Class</a></li><li  class=""><a href="../development/legacy/database/connecting-to-an-external-database.html">Connecting to an External Database</a></li></ul></li><li  class=""><a href="../development/legacy/helpers/index.html">Helpers</a><ul><li  class=""><a href="../development/legacy/helpers/array-helper.html">Array Helper</a></li><li  class=""><a href="../development/legacy/helpers/cookie-helper.html">Cookie Helper</a></li><li  class=""><a href="../development/legacy/helpers/directory-helper.html">Directory Helper</a></li><li  class=""><a href="../development/legacy/helpers/download-helper.html">Download Helper</a></li><li  class=""><a href="../development/legacy/helpers/file-helper.html">File Helper</a></li><li  class=""><a href="../development/legacy/helpers/form-helper.html">Form Helper</a></li><li  class=""><a href="../development/legacy/helpers/html-helper.html">HTML Helper</a></li><li  class=""><a href="../development/legacy/helpers/language-helper.html">Language Helper</a></li><li  class=""><a href="../development/legacy/helpers/number-helper.html">Number Helper</a></li><li  class=""><a href="../development/legacy/helpers/path-helper.html">Path Helper</a></li><li  class=""><a href="../development/legacy/helpers/security-helper.html">Security Helper</a></li><li  class=""><a href="../development/legacy/helpers/string-helper.html">String Helper</a></li><li  class=""><a href="../development/legacy/helpers/text-helper.html">Text Helper</a></li><li  class=""><a href="../development/legacy/helpers/url-helper.html">URL Helper</a></li><li  class=""><a href="../development/legacy/helpers/xml-helper.html">XML Helper</a></li></ul></li><li  class=""><a href="../development/legacy/api/index.html">Legacy API Library</a><ul><li  class=""><a href="../development/legacy/api/api-channel-categories.html">Channel Categories API</a></li><li  class=""><a href="../development/legacy/api/api-channel-fields.html">Channel Fields API</a></li><li  class=""><a href="../development/legacy/api/api-channel-structure.html">Channel Structure API</a></li><li  class=""><a href="../development/legacy/api/api-template-structure.html">Template Structure API</a></li></ul></li></ul></li><li  class=""><a >Guidelines</a><ul><li  class=""><a href="../development/guidelines/index.html">Overview</a></li><li  class=""><a href="../development/guidelines/checklist.html">Guidelines Checklist</a></li><li  class=""><a href="../development/guidelines/general.html">General Style and Syntax</a></li><li  class=""><a href="../development/guidelines/in-app-documentation.html">In-app Documentation</a></li><li  class=""><a href="../development/guidelines/performance.html">Performance Guidelines</a></li><li  class=""><a href="../development/guidelines/security.html">Security Guidelines</a></li><li  class=""><a href="../development/guidelines/view-php-syntax.html">View Files and PHP Syntax</a></li></ul></li><li  class=""><a href="../development/v4-addon-migration.html">v4 Add-on Migration</a></li><li  class=""><a href="../development/v3-add-on-migration.html">v3 Add-on Migration</a></li></ul></li><li  class=""><a href="../bugs-and-security-reports.html">Bugs and Security Reports</a></li><li  class=""><a href="../style-guide.html">Docs Style Guide</a></li></ul>
				</div>
			</div>
		</div>

		<section class="docs-content-wrapper">
			<div class="content" id="docsearch-content">
				<!--
    This source file is part of the open source project
    ExpressionEngine User Guide (https://github.com/ExpressionEngine/ExpressionEngine-User-Guide)

    @link      https://expressionengine.com/
    @copyright Copyright (c) 2003-2020, Packet Tide, LLC (https://www.packettide.com)
    @license   https://expressionengine.com/license Licensed under Apache License, Version 2.0
-->


		<h1>
		<span class="anchor" id="conditional-tags"></span>
		<a href="#conditional-tags">Conditional Tags</a>
		</h1><div class="table-of-contents"><ul>
<li><a href="#protected-characters">Protected Characters</a></li>
<li><a href="#boolean-values-true-and-false">Boolean Values (True and False)</a></li>
<li><a href="#operators">Operators</a></li>
<li><a href="#else-and-elseif">Else and Elseif</a></li>
<li><a href="#embedding-tags">Embedding Tags</a></li>
<li><a href="#short-conditionals">Short Conditionals</a></li>
<li><a href="#global-conditional-variables">Global Conditional Variables</a></li>
<li><a href="#errors">Errors</a></li>
</ul>
</div><p>Conditional Tags are pair tags, which allow you to conditionally show or hide information on your pages based on criteria being met. They take on this general form:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> condition}</span><span class="xml"> data to show if condition is met </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>The syntax available for the condition is comparable to most programming languages. Some examples:</p><pre><code><span class="xml"></span><span class="hljs-comment">{!-- Basic truth tests --}</span><span class="xml">
</span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> logged_in}</span><span class="xml">Welcome back.</span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml">

</span><span class="hljs-comment">{!-- Comparisons --}</span><span class="xml">
</span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> username == <span class="hljs-string">'Bob'</span>}</span><span class="xml">Welcome back, Bob!</span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml">

</span><span class="hljs-comment">{!-- Math --}</span><span class="xml">
</span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> (age + <span class="hljs-number">5</span>) == <span class="hljs-number">100</span>}</span><span class="xml">Five years to go!</span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml">

</span><span class="hljs-comment">{!-- Logical operators --}</span><span class="xml">
</span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> age == <span class="hljs-number">30</span> <span class="hljs-keyword">AND</span> username == <span class="hljs-string">'Bob'</span>}</span><span class="xml">Welcome back, Bob. 30 is the new 20.</span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml">

</span><span class="hljs-comment">{!-- Branching --}</span><span class="xml">
</span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> age == <span class="hljs-number">30</span>}</span><span class="xml">
  You are 30!
</span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if:elseif</span></span> username == <span class="hljs-string">'Bob'</span>}</span><span class="xml">
  You are Bob!
</span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if:else</span></span>}</span><span class="xml">
  You're not 30 or Bob. That's all we know.
</span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre>
		<h2>
		<span class="anchor" id="protected-characters"></span>
		<a href="#protected-characters">Protected Characters</a>
		</h2><p>Certain characters must be protected in conditionals to prevent them from being mistaken for regular ExpressionEngine tags:</p><div class="table-wrapper"><table><thead><tr>
<th>To evaluate</th>
<th>Use instead</th>
</tr>
</thead><tbody><tr>
<td>{</td>
<td><code>&amp;#123;</code></td>
</tr>
<tr>
<td>}</td>
<td><code>&amp;#125;</code></td>
</tr>
<tr>
<td>\n (linebreaks)</td>
<td>space</td>
</tr>
<tr>
<td>\r (carriage return)</td>
<td>space</td>
</tr>
<tr>
<td>\t (tab)</td>
<td>space</td>
</tr>
</tbody></table></div><p>If you are comparing a variable against a value that might include curly braces, then you should use the HTML entities listed in the table above instead. For example, if you want the conditional to evaluate whether the title is <em>Curly and the Braces: {}</em>, you would write the conditional like so:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> title == <span class="hljs-string">'Curly and the Braces: &amp;#123;&amp;#125;'</span>}</span><span class="xml"></span></code></pre>
		<h2>
		<span class="anchor" id="boolean-values-true-and-false"></span>
		<a href="#boolean-values-true-and-false">Boolean Values (True and False)</a>
		</h2><p>When determining Boolean values the following are considered <strong>FALSE</strong>:</p><ul>
<li>the keyword <code>FALSE</code></li>
<li>the integer <code>0</code></li>
<li>the floating point number <code>0.0</code></li>
<li>an empty string <code>&quot;&quot;</code> or <code>&#39;&#39;</code></li>
</ul>
<p>Everything else is considered <strong>TRUE</strong>.</p><p><strong>Note:</strong> The string <code>&quot;0&quot;</code> is considered <strong>TRUE</strong> since it is a non-empty string.</p>
		<h2>
		<span class="anchor" id="operators"></span>
		<a href="#operators">Operators</a>
		</h2><p>The following operators are allowed within conditionals:</p>
		<h3>
		<span class="anchor" id="comparison-operators"></span>
		<a href="#comparison-operators">Comparison Operators</a>
		</h3><p>You can use any of the following operators to compare a variable to a value:</p><div class="table-wrapper"><table><thead><tr>
<th>Operator</th>
<th>Name</th>
</tr>
</thead><tbody><tr>
<td>==</td>
<td>Equal</td>
</tr>
<tr>
<td>!=</td>
<td>Not Equal</td>
</tr>
<tr>
<td>&lt;&gt;</td>
<td>Not equal</td>
</tr>
<tr>
<td>&lt;</td>
<td>Less than</td>
</tr>
<tr>
<td>&lt;=</td>
<td>Less than or equal to</td>
</tr>
<tr>
<td>&gt;</td>
<td>Greater than</td>
</tr>
<tr>
<td>&gt;=</td>
<td>Greater than or equal to</td>
</tr>
<tr>
<td>^=</td>
<td>Begins with <begins_with_operator></td>
</tr>
<tr>
<td>*=</td>
<td>Contains <contains_operator></td>
</tr>
<tr>
<td>$=</td>
<td>Ends with <ends_with_operator></td>
</tr>
<tr>
<td>~</td>
<td>Matches <matches_operator></td>
</tr>
</tbody></table></div><p class="alert alert--warn"> <strong>Note:</strong> When comparing equality make sure to use <strong>two</strong> equal signs rather than one (e.g. <strong>==</strong>).</p>
		<h4>
		<span class="anchor" id="begins-with-operator"></span>
		<a href="#begins-with-operator">Begins With Operator</a>
		</h4><p>The begins with operator checks if a string begins with another string:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> <span class="hljs-string">"ExpressionEngine"</span> ^= <span class="hljs-string">"Express"</span>}</span><span class="xml">Yes it does</span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre>
		<h4>
		<span class="anchor" id="ends-with-operator"></span>
		<a href="#ends-with-operator">Ends With Operator</a>
		</h4><p>The ends with operator checks if a string ends with another string:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> url $= <span class="hljs-string">".fr"</span>}</span><span class="xml">Your website is from France.</span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre>
		<h4>
		<span class="anchor" id="contains-operator"></span>
		<a href="#contains-operator">Contains Operator</a>
		</h4><p>The contains operator checks if a string contains another string:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> body *= excerpt}</span><span class="xml">Noone expected that.</span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre>
		<h4>
		<span class="anchor" id="matches-operator"></span>
		<a href="#matches-operator">Matches Operator</a>
		</h4><p>The matches operator checks if a string matches a regular expression:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> segment_3 ~ <span class="hljs-string">"/^P\d+/"</span>}</span><span class="xml">paginated</span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p class="alert alert--warn"> <strong>Note:</strong> The second value must be a valid regular expression. All <a href="http://us1.php.net/manual/en/reference.pcre.pattern.modifiers.php">PHP PCRE pattern modifiers</a> are allowed.</p>
		<h5>
		<span class="anchor" id="using-comparison-operators-with-numbers"></span>
		<a href="#using-comparison-operators-with-numbers">Using Comparison Operators with Numbers</a>
		</h5><p>These operators will work with both numbers and strings, but with numbers it’s important to remember that they will be turned into an unambiguous representation. This means that redundant leading and trailing zeros are removed. Floating point numbers &lt; 1 will have a leading zero added if it is not present:</p><pre><code>.7 becomes 0.7
1. becomes 7
.20 becomes 0.2
0002 becomes 2
002.5000 becomes 2.5</code></pre><p>This can be avoided by quoting your numbers:</p><pre><code>{<span class="hljs-keyword">if</span> <span class="hljs-number">42.7</span> $= <span class="hljs-number">.7</span>} - <span class="hljs-literal">false</span>, <span class="hljs-number">42.7</span> does not end <span class="hljs-keyword">with</span> <span class="hljs-number">0.7</span>
{<span class="hljs-keyword">if</span> <span class="hljs-number">42.7</span> $= <span class="hljs-string">'.7'</span>} - <span class="hljs-literal">true</span>
{<span class="hljs-keyword">if</span> <span class="hljs-string">'42.7'</span> $= <span class="hljs-string">'.7'</span>} - <span class="hljs-literal">true</span>

{<span class="hljs-keyword">if</span> <span class="hljs-number">42.70</span> $= <span class="hljs-number">70</span>} - <span class="hljs-literal">false</span>, <span class="hljs-number">42.7</span> does not end <span class="hljs-keyword">in</span> <span class="hljs-number">70</span>
{<span class="hljs-keyword">if</span> <span class="hljs-string">'42.70'</span> $= <span class="hljs-number">70</span>} - <span class="hljs-literal">true</span>
{<span class="hljs-keyword">if</span> <span class="hljs-string">'42.70'</span> $= <span class="hljs-string">'70'</span>} - <span class="hljs-literal">true</span></code></pre>
		<h3>
		<span class="anchor" id="logical-operators"></span>
		<a href="#logical-operators">Logical Operators</a>
		</h3><p>You can use the following operators to compare true / false (boolean) values. In this context strings that are not empty, numbers that are not 0, and the TRUE keyword are all true. Everything else is false.</p><div class="table-wrapper"><table><thead><tr>
<th>Operator</th>
<th>Name</th>
<th>Result</th>
</tr>
</thead><tbody><tr>
<td>!</td>
<td>Not</td>
<td>TRUE if the following value is FALSE.</td>
</tr>
<tr>
<td>&amp;&amp;</td>
<td>And</td>
<td>TRUE if both values are TRUE.</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>AND</td>
<td>And</td>
<td>TRUE if both values are TRUE.</td>
</tr>
<tr>
<td>XOR</td>
<td>Xor</td>
<td>TRUE if either value is TRUE, but not both.</td>
</tr>
<tr>
<td>OR</td>
<td>Or</td>
<td>TRUE if either value is TRUE.</td>
</tr>
</tbody></table></div><p>These operators let you create complex rules for your templates:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> member_id != <span class="hljs-string">'1'</span> &amp;&amp; member_group != <span class="hljs-string">"5"</span> <span class="hljs-keyword">OR</span> username == <span class="hljs-string">"Billy"</span>}</span><span class="xml"> Hi! </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre>
		<h3>
		<span class="anchor" id="mathematic-operators"></span>
		<a href="#mathematic-operators">Mathematic Operators</a>
		</h3><p>You can use the following mathematical operators to compute values:</p><div class="table-wrapper"><table><thead><tr>
<th>Operator</th>
<th>Name</th>
</tr>
</thead><tbody><tr>
<td>+</td>
<td>Addition</td>
</tr>
<tr>
<td>-</td>
<td>Subtraction / Negation</td>
</tr>
<tr>
<td>*</td>
<td>Multiplication</td>
</tr>
<tr>
<td>** and ^</td>
<td>Exponentiation</td>
</tr>
<tr>
<td>/</td>
<td>Division</td>
</tr>
<tr>
<td>%</td>
<td>Remainder of one number divided by another</td>
</tr>
</tbody></table></div><p class="alert alert--warn"> <strong>Note:</strong> When using these mathematical operators be sure to surround them with whitespace. Consider that <code>foo-bar</code> is a valid variable while <code>foo - bar</code> indicates subtraction.</p>
		<h4>
		<span class="anchor" id="modulus-operator"></span>
		<a href="#modulus-operator">Modulus Operator</a>
		</h4><p>A modulus operator finds the remainder of division of one number by another. This can be handy when you want to do something every nth iteration of a loop. For example, if we want to display a horizontal rule for every 5th entry in a <a href="../channels/entries.html">Channel Entries</a> loop, we would write this conditional:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> count % <span class="hljs-number">5</span> == <span class="hljs-number">0</span>}</span><span class="xml">
  <span class="hljs-tag">&lt;<span class="hljs-name">hr</span>&gt;</span>
</span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>This works because the remainder of 5 divided by 5 is 0.</p>
		<h4>
		<span class="anchor" id="exponent-operators"></span>
		<a href="#exponent-operators">Exponent Operators</a>
		</h4><p>There are two exponent operators: <code>**</code> and <code>^</code>. They are treated the same, so use whichever you prefer:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> count ** <span class="hljs-number">2</span> == <span class="hljs-number">25</span>}</span><span class="xml">What a strange way ...</span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml">
</span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> count ^ <span class="hljs-number">2</span> == <span class="hljs-number">25</span>}</span><span class="xml">... to check if count is 5</span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre>
		<h3>
		<span class="anchor" id="exponentiation-of-negatives"></span>
		<a href="#exponentiation-of-negatives">Exponentiation of Negatives</a>
		</h3><p>Negation happens <em>after</em> exponentiation. The following are true:</p><pre><code>-5 ** 2 == -25
(-5) ** 2 == 25</code></pre><p>This is easy to remember, by keeping in mind that subtraction always happens after exponentiation. Of course, if the minus is itself in the exponent, then it is applied first:</p><pre><code>5 ** -2 == 0.04</code></pre>
		<h3>
		<span class="anchor" id="multiple-exponentiation"></span>
		<a href="#multiple-exponentiation">Multiple Exponentiation</a>
		</h3><p>Exponents are processed from right to left. This means that <code>2 ^ 3 ^ 2</code> is treated as <code>2 ^ 9</code>, not as <code>8 ^ 2</code>:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> <span class="hljs-number">2</span> ^ <span class="hljs-number">3</span> ^ <span class="hljs-number">2</span> == <span class="hljs-number">512</span>}</span><span class="xml">this</span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml">
</span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> <span class="hljs-number">2</span> ^ <span class="hljs-number">3</span> ^ <span class="hljs-number">2</span> == <span class="hljs-number">64</span>}</span><span class="xml">not this</span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre>
		<h3>
		<span class="anchor" id="string-concatenation-operator"></span>
		<a href="#string-concatenation-operator">String Concatenation Operator</a>
		</h3><p>You can use the string concatenation operator (<code>.</code>) to concatenate values:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> segment_1 . <span class="hljs-string">'/'</span> . segment_2 == <span class="hljs-string">'site/index'</span>}</span><span class="xml"></span></code></pre>
		<h3>
		<span class="anchor" id="parentheses-in-conditionals"></span>
		<a href="#parentheses-in-conditionals">Parentheses in Conditionals</a>
		</h3><p>You can use parentheses to group parts of a conditional together to have the part of the conditional between the parentheses evaluate before being compared to the part of the conditional outside the parentheses. For example, in the code below, the two member group parts are evaluated <em>first</em> before their result is compared to the channel_id part of the conditional:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> (member_id == <span class="hljs-string">'1'</span> <span class="hljs-keyword">OR</span> member_id == <span class="hljs-string">'2'</span>) &amp;&amp; channel_id == <span class="hljs-string">'5'</span>}</span><span class="xml"></span></code></pre><p>So, if the member id of the visitor is either 1 or 2, and they are viewing the channel with id of 5, then they can see the contents of that conditional.</p>
		<h2>
		<span class="anchor" id="else-and-elseif"></span>
		<a href="#else-and-elseif">Else and Elseif</a>
		</h2><p>You can use two additional control structures to help tailor your results:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if:elseif</span></span>}</span><span class="xml"></span></code></pre><p>And:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if:else</span></span>}</span><span class="xml"></span></code></pre><p>These work similar to standard PHP else and elseif constructs. Here is an example:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> username == <span class="hljs-string">"Joe"</span>}</span><span class="xml">
  <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Hey, Joe! Where were you Tuesday?<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
</span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if:elseif</span></span> username == <span class="hljs-string">"Bob"</span>}</span><span class="xml">
  <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Hey, Bob! Thanks for the tickets!<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
</span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if:else</span></span>}</span><span class="xml">
  <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Welcome to our site.<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
</span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>In the above example, if the currently logged in user has the username of “joe” he receives the first message. If not, ExpressionEngine evaluates the second conditional for the username of “bob”. If the username is neither joe nor bob a default message is shown.</p><p class="alert alert--warn"> <strong>Note:</strong> Don’t be confused by the <em>{if:</em> prefix. This simply helps the parsing engine identify each control structure. The information to the <em>right</em> of the prefix is what determines which conditional you are using.</p>
		<h2>
		<span class="anchor" id="embedding-tags"></span>
		<a href="#embedding-tags">Embedding Tags</a>
		</h2><p>We recommend not wrapping variables in braces (<code>{}</code>) for example, do this:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> my_snippet == <span class="hljs-string">"hello world"</span>}</span><span class="xml"></span></code></pre><p>instead of these:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> {my_snippet}</span><span class="xml"> == "hello world"}
</span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> <span class="hljs-string">"{my_snippet}"</span> == <span class="hljs-string">"hello world"</span>}</span><span class="xml"></span></code></pre><p class="alert alert--hint"> <strong>Tip:</strong> As a general rule, you should never brace your conditional variables, which allows ExpressionEngine to optimize for the best performance and security.</p><p>☣ <strong>Technical content ahead:</strong> Braced variables in a conditional are literally output to the template like they are anywhere else before evaluating. So rather than being able to use a lightweight internal PHP variable, ExpressionEngine has to compare string literals. If a lot of text-based content is involved, then you could be creating strain on the application due to internal constraints of PHP and the server’s regular expression libraries.</p><p>There are a few exceptions to this where bracing is required or even recommended. This is the case for certain types of metadata, where the type, length, and nature of the content is known. In other words, variables that belong to the system, and whose contents are not influenced or created by a content author. For example, comparing formatted dates:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> <span class="hljs-string">"{entry_date format='%Y'}"</span> == <span class="hljs-string">"{current_time format='%'}"</span>}</span><span class="xml"></span></code></pre><p>When using tags pay special attention to your quote marks. If you need more than one level of quotation you will need to either alternate between single and double quote marks, or escape your quotes. For example, instead of this (the problem should be apparent by the syntax highlighting):</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> <span class="hljs-string">"{current_time format="</span>%F<span class="hljs-string">"}"</span> == <span class="hljs-string">"May"</span>}</span><span class="xml"></span></code></pre><p>do this:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> <span class="hljs-string">"{current_time format='%F'}"</span> == <span class="hljs-string">"May"</span>}</span><span class="xml"></span></code></pre><p>or this:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> <span class="hljs-string">"{current_time format=\"%F\"}"</span> == <span class="hljs-string">"May"</span>}</span><span class="xml"></span></code></pre><p>Tags that output numeric content will work fine with quotes, but also do not need them, e.g. <a href="../fieldtypes/fluid.html">Fluid field count variables</a>:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> {fluid_content:count <span class="hljs-attr">type</span>=<span class="hljs-string">"long_form_text"</span>}</span><span class="xml"> == 3}</span></code></pre>
		<h2>
		<span class="anchor" id="short-conditionals"></span>
		<a href="#short-conditionals">Short Conditionals</a>
		</h2><p>Certain conditionals exist in a shortened form in order to improve template readability. These conditionals are usually checking to see if a certain thing is true or exists:</p>
		<h3>
		<span class="anchor" id="examples"></span>
		<a href="#examples">Examples</a>
		</h3>
		<h4>
		<span class="anchor" id="if-logged_in"></span>
		<a href="#if-logged_in"><code>if logged_in</code></a>
		</h4><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> logged_in}</span><span class="xml">  Welcome back to the site!<span class="hljs-tag">&lt;<span class="hljs-name">br</span> /&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"</span></span></span><span class="hljs-template-tag">{<span class="hljs-name">path</span>=<span class="hljs-string">'LOGOUT'</span>}</span><span class="xml"><span class="hljs-tag"><span class="hljs-string">"</span>&gt;</span>Logout<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>  </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>This tag pair will display content within the pair if the person viewing the page is currently a logged in member.</p><p class="alert alert--warn"> <strong>Note:</strong> This only tests whether or not someone is logged in. If you want to restrict a particular page based on the member group assignment you’ll do that in your Template preferences in the Control Panel.</p>
		<h4>
		<span class="anchor" id="if-logged_out"></span>
		<a href="#if-logged_out"><code>if logged_out</code></a>
		</h4><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> logged_out}</span><span class="xml">
    You aren't a member or aren't logged in.<span class="hljs-tag">&lt;<span class="hljs-name">br</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"</span></span></span><span class="hljs-template-tag">{<span class="hljs-name">path</span>=<span class="hljs-string">'member/login'</span>}</span><span class="xml"><span class="hljs-tag"><span class="hljs-string">"</span>&gt;</span>Login<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>  | <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"</span></span></span><span class="hljs-template-tag">{<span class="hljs-name">path</span>=<span class="hljs-string">'member/register'</span>}</span><span class="xml"><span class="hljs-tag"><span class="hljs-string">"</span>&gt;</span>Register<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>This tag pair will display content within the pair if the person viewing the page is <strong>not</strong> currently a logged in member.</p><p>You’ll notice in the “logout” link above that a special path is used: {path=’LOGOUT’}. This is a special-case path value that will automatically render the correct path for someone to log out.</p>
		<h2>
		<span class="anchor" id="global-conditional-variables"></span>
		<a href="#global-conditional-variables">Global Conditional Variables</a>
		</h2><p>There are a handful of variables that are always available to conditionals.</p>
		<h3>
		<span class="anchor" id="logged_in_email"></span>
		<a href="#logged_in_email"><code>logged_in_email</code></a>
		</h3><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> logged_in_email $= <span class="hljs-string">'example.com'</span>}</span><span class="xml">  One of us! One of us!  </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>You can test against the email address of the currently logged in user.</p>
		<h3>
		<span class="anchor" id="logged_in_group_description"></span>
		<a href="#logged_in_group_description"><code>logged_in_group_description</code></a>
		</h3><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> logged_in_group_description *= <span class="hljs-string">'games'</span>}</span><span class="xml">  Shall we play a game?  </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>You can test against the group description of the currently logged in user.</p>
		<h3>
		<span class="anchor" id="logged_in_group_id"></span>
		<a href="#logged_in_group_id"><code>logged_in_group_id</code></a>
		</h3><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> logged_in_group_id == <span class="hljs-string">'7'</span>}</span><span class="xml">  You're an "Editor"!  </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>You can test against the Member Group of the currently logged in user.</p>
		<h3>
		<span class="anchor" id="logged_in_ip_address"></span>
		<a href="#logged_in_ip_address"><code>logged_in_ip_address</code></a>
		</h3><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> logged_in_ip_address == <span class="hljs-string">'127.0.0.1'</span>}</span><span class="xml">  There's no place like home.  </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>You can test against the IP address of the currently logged in user.</p>
		<h3>
		<span class="anchor" id="logged_in_location"></span>
		<a href="#logged_in_location"><code>logged_in_location</code></a>
		</h3><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> logged_in_location *= <span class="hljs-string">'Vulcan'</span>}</span><span class="xml">  Live long and prosper.  </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>You can test against the location of the currently logged in user.</p>
		<h3>
		<span class="anchor" id="logged_in_member_id"></span>
		<a href="#logged_in_member_id"><code>logged_in_member_id</code></a>
		</h3><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> logged_in_member_id == <span class="hljs-string">'147'</span>}</span><span class="xml">  Ooh, you're really special, Frank!!  </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>Test for the member ID of the currently logged in user.</p>
		<h3>
		<span class="anchor" id="logged_in_private_messages"></span>
		<a href="#logged_in_private_messages"><code>logged_in_private_messages</code></a>
		</h3><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> logged_in_private_messages &gt; <span class="hljs-number">0</span>}</span><span class="xml">  You have unread private messages.  </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>Test against the number of unread private messages.</p>
		<h3>
		<span class="anchor" id="logged_in_screen_name"></span>
		<a href="#logged_in_screen_name"><code>logged_in_screen_name</code></a>
		</h3><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> logged_in_screen_name == <span class="hljs-string">"Mr. Ed"</span>}</span><span class="xml">  Thanks for all your hard work on the site, Ed!  </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>You can test against the screen name of the currently logged in user.</p>
		<h3>
		<span class="anchor" id="logged_in_total_comments"></span>
		<a href="#logged_in_total_comments"><code>logged_in_total_comments</code></a>
		</h3><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> logged_in_total_comments &lt; <span class="hljs-number">1</span>}</span><span class="xml">  Care to comment?  </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>Test against the total number of comments submitted by the currently logged in user.</p>
		<h3>
		<span class="anchor" id="logged_in_total_entries"></span>
		<a href="#logged_in_total_entries"><code>logged_in_total_entries</code></a>
		</h3><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> logged_in_total_entries &gt; <span class="hljs-number">1000</span>}</span><span class="xml">  Gold star contributor!  </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>Test against the total number of entries submitted by the currently logged in user.</p>
		<h3>
		<span class="anchor" id="logged_in_total_forum_posts"></span>
		<a href="#logged_in_total_forum_posts"><code>logged_in_total_forum_posts</code></a>
		</h3><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> logged_in_total_forum_posts &gt; <span class="hljs-number">1000</span>}</span><span class="xml">  Loquacious aren't we?  </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>Test against the total number of forum posts by the currently logged in user.</p>
		<h3>
		<span class="anchor" id="logged_in_total_forum_topics"></span>
		<a href="#logged_in_total_forum_topics"><code>logged_in_total_forum_topics</code></a>
		</h3><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> logged_in_total_forum_topics &lt; <span class="hljs-number">1</span>}</span><span class="xml">  Care to start something?  </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>Test against the total number of forum topics by the currently logged in user.</p>
		<h3>
		<span class="anchor" id="logged_in_username"></span>
		<a href="#logged_in_username"><code>logged_in_username</code></a>
		</h3><pre><code><span class="xml">`</span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> username != <span class="hljs-string">"HAL9000"</span>}</span><span class="xml">  I'm sorry Dave, I'm afraid I can't do that.  </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml">`</span></code></pre><p>You can test against the username of the currently logged in user.</p>
		<h3>
		<span class="anchor" id="segment_x"></span>
		<a href="#segment_x"><code>segment_*X*</code></a>
		</h3><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> segment_3 == <span class="hljs-string">"private"</span>}</span><span class="xml">  You're seeing something private!  </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>You can test against one of the <a href="../templates/globals/url-segments.html">URL Segments</a> that are available. The conditional should be replaced with the correct segment name. e.g. if you’re interested in URL Segment 3, then use <code>{if segment_3}</code>.</p>
		<h3>
		<span class="anchor" id="total_comments"></span>
		<a href="#total_comments"><code>total_comments</code></a>
		</h3><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> total_comments &lt; <span class="hljs-number">1</span>}</span><span class="xml">  What??  No one has commented on my site at all?!?!  </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>Test against the total number of comments submitted for the entire site.</p>
		<h3>
		<span class="anchor" id="total_entries"></span>
		<a href="#total_entries"><code>total_entries</code></a>
		</h3><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> total_entries &gt; <span class="hljs-number">1000</span>}</span><span class="xml">  Yowza!  This is one hot site!  </span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>Test against the total number of entries submitted for the entire site.</p>
		<h2>
		<span class="anchor" id="errors"></span>
		<a href="#errors">Errors</a>
		</h2><p>In the event that there is a problem parsing or evaluating a conditional an error will be displayed based on your <a href="../control-panel/settings/debug-output.html#enable-error-reporting">debug preferences</a>. Errors are triggered in the following scenarios:</p><ul>
<li><code>{if:</code> is encountered in the template without it being either <code>if:else</code> or <code>if:elseif</code>. For example:</li>
</ul>
<!-- -->

<pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name">if:foo</span>}</span><span class="xml"></span></code></pre><ul>
<li><p><code>{/if}</code> cannot be found. All <code>{/if}</code> inside a string (single or double-quoted) are ignored. For example:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> segment_1 == <span class="hljs-string">'site'</span>}</span><span class="xml">HELLO WORLD</span></code></pre></li>
<li><p>There is an unclosed single or double-quoted string. For example:</p></li>
</ul>
<!-- -->

<pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> segment_1 == <span class="hljs-string">"site}HELLO WORLD{/if}</span></span></code></pre><ul>
<li>A closing <code>}</code> is not found. For example:</li>
</ul>
<!-- -->

<pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> segment_1 == <span class="hljs-string">"site"</span> HELLO WORLD{/if}</span><span class="xml"></span></code></pre><ul>
<li><p>A valid operator is not found. For example:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> segment_1 <span class="hljs-string">"site"</span>}</span><span class="xml">HELLO WORLD</span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre><p>or:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> segment_1 ==== <span class="hljs-string">"site"</span>}</span><span class="xml">HELLO WORLD</span><span class="hljs-template-tag">{/<span class="hljs-name"><span class="hljs-keyword">if</span></span>}</span><span class="xml"></span></code></pre></li>
<li><p>A number followed by a colon (<code>:</code>) was found. For example:</p></li>
</ul>
<!-- -->

<pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> <span class="hljs-number">5</span>:<span class="hljs-number">2</span>}</span><span class="xml"></span></code></pre><ul>
<li><p>A number has too many periods (<code>.</code>). For example:</p><pre><code><span class="xml"></span><span class="hljs-template-tag">{<span class="hljs-name"><span class="hljs-keyword">if</span></span> <span class="hljs-number">1.2</span>.<span class="hljs-number">3</span>}</span><span class="xml"></span></code></pre></li>
</ul>


				<hr>

				<p class="docs-footer">
					<span>ExpressionEngine 5.4.2 Docs
					<br>
					<span class="copyright"><a href="https://packettide.com/">©2002–2021 Packet Tide,LLC.</a></span>
					</span>
					<a target="_blank" class="docs-contribute-to-page-button" href="https://github.com/ExpressionEngine/ExpressionEngine-User-Guide/blob/stability/docs/templates/conditionals.md">Edit this page</a>
				</p>
			</div>
		</section>

		<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script>
		<script type="text/javascript">
			docsearch({
				apiKey: 'ba20cc61ab2d8a0148041c98eeddd9c6',
				indexName: 'expressionengine',
				inputSelector: '#docsearch-input',
				algoliaOptions: { 'facetFilters': ["version:v5"] },
				debug: false
			});
		</script>

		<script src="../_assets/main.min.js"></script>
	</body>
</html>



