{"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"if-and-else-tags","__idx":0},"children":["If and else tags"]},{"$$mdtype":"Tag","name":"ConfigOptionRequirements","attributes":{"products":["Revel","Reef","Realm"],"plans":["Pro","Enterprise","Enterprise+"]},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["if"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["else"]}," tags let you conditionally render content in Markdoc."," ","Use these tags with variables and functions to show the right content for the right user or context."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"syntax-and-usage","__idx":1},"children":["Syntax and usage"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["if"]}," when you want content to render only when a condition is true."," ","Add ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["else"]}," when you want fallback content when the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["if"]}," condition is not met."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Example syntax:"]}]},{"$$mdtype":"Tag","name":"MarkdocExample","attributes":{"renderDemo":false,"language":"markdoc","demoContent":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This guide shows a high-level overview."]}],"rawContent":"{% if equals($frontmatter.audience, \"developer\") %}\nThis guide shows advanced API setup steps.\n{% else /%}\nThis guide shows a high-level overview.\n{% /if %}\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In Realm, you can chain multiple ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["else"]}," branches with conditions."," ","The final ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["else /%"]}," branch acts as the default fallback."]},{"$$mdtype":"Tag","name":"MarkdocExample","attributes":{"renderDemo":false,"language":"markdoc","demoContent":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Upgrade to unlock this section."]}],"rawContent":"{% if equals($userClaims.plan, \"enterprise\") %}\nAccess to enterprise-only docs.\n{% else equals($userClaims.plan, \"pro\") /%}\nAccess to pro docs.\n{% else /%}\nUpgrade to unlock this section.\n{% /if %}\n"},"children":[]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"warning","name":"Values in Markdoc"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Markdoc treats only ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["undefined"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["null"]},", and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["false"]}," as falsy."," ","Values like ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["0"]},", empty strings, and empty arrays are treated as truthy."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"conditional-function-reference","__idx":2},"children":["Conditional function reference"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use built-in functions to keep conditional expressions readable and composable."]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Function"},"children":["Function"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Returns"},"children":["Returns"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Description"},"children":["Description"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["equals"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["boolean"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Compares values using strict equality."," ","Useful for role, plan, or environment checks."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["and"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["boolean"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Returns true when all parameters are truthy."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["or"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["boolean"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Returns true when at least one parameter is truthy."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["not"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["boolean"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Negates a boolean expression."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["default"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["mixed"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Returns a fallback value when the first parameter is undefined."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["debug"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Serializes a value as JSON for debugging."," ","Useful when testing variables in a condition."]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"examples","__idx":3},"children":["Examples"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The following examples show common conditional patterns for documentation."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"gate-content-using-the-front-matter","__idx":4},"children":["Gate content using the front matter"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use front matter variables to switch content variants in one page."]},{"$$mdtype":"Tag","name":"MarkdocExample","attributes":{"renderDemo":false,"language":"markdoc","demoContent":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This feature is generally available."]}],"rawContent":"---\nreleaseStage: beta\n---\n\n{% if equals($frontmatter.releaseStage, \"beta\") %}\n{% admonition type=\"warning\" %}\nThis feature is in beta and may change.\n{% /admonition %}\n{% else /%}\nThis feature is generally available.\n{% /if %}\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"combine-built-in-functions","__idx":5},"children":["Combine built-in functions"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Compose conditions for more specific rules."]},{"$$mdtype":"Tag","name":"MarkdocExample","attributes":{"renderDemo":false,"language":"markdoc","demoContent":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You need an active premium subscription."]}],"rawContent":"{% if and(equals($userClaims.role, \"customer\"), not($userClaims.isExpired)) %}\nPremium customer content.\n{% else /%}\nYou need an active premium subscription.\n{% /if %}\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"use-a-custom-function-with-if-and-else","__idx":6},"children":["Use a custom function with if and else"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Custom functions make repeated business logic reusable for authors."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Example function definition:"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","data-title":"@theme/markdoc/schema.ts","header":{"title":"@theme/markdoc/schema.ts","controls":{"copy":{}}},"source":"export const functions = {\n  isAfterDate: {\n    transform(parameters) {\n      const inputDateString = parameters[0];\n      const inputDate = new Date(inputDateString);\n      const currentDate = new Date();\n      currentDate.setHours(0, 0, 0, 0);\n\n      return inputDate < currentDate;\n    }\n  }\n};\n","lang":"typescript"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Example usage in content:"]}]},{"$$mdtype":"Tag","name":"MarkdocExample","attributes":{"renderDemo":false,"language":"markdoc","demoContent":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["No active promotion."]}],"rawContent":"{% if and(isAfterDate(\"2026-06-01\"), not(isAfterDate(\"2026-07-01\"))) %}\n{% admonition type=\"info\" name=\"Sale\" %}\nLimited-time offer is active.\n{% /admonition %}\n{% else /%}\nNo active promotion.\n{% /if %}\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"best-practices","__idx":7},"children":["Best practices"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Conditional tags are most useful when they improve relevance without making the document hard to maintain."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Keep conditions readable"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Prefer simple expressions."," ","Move repeated logic into custom functions."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Always include a fallback"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use a final ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["else /%"]}," branch when content can be hidden for some users."," ","Fallback text prevents empty sections."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Use stable variables"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Base conditions on predictable values such as front matter, user claims, or environment flags."," ","Avoid conditions that rely on inconsistent runtime data."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Test both paths"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Preview pages with values that trigger both ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["if"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["else"]}," branches."," ","Confirm that hidden content does not leave confusing gaps."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"resources","__idx":8},"children":["Resources"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":[{"$$mdtype":"Tag","name":"Link","attributes":{"href":"/docs/realm/customization/build-custom-function"},"children":["Build Markdoc functions"]}]}," - Follow a tutorial for adding custom functions in a Redocly Realm project"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":[{"$$mdtype":"Tag","name":"Link","attributes":{"href":"https://redocly.com/learn/markdoc"},"children":["Markdoc overview for technical writers"]}]}," - Learn how to make your content dynamic with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["if"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["else"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":[{"$$mdtype":"Tag","name":"Link","attributes":{"href":"/docs/realm/content/markdoc-tags"},"children":["Markdoc tags"]}]}," - See the full list of supported Markdoc tags"]}]}]},"frontmatter":{"products":["Revel","Reef","Realm"],"plans":["Pro","Enterprise","Enterprise+"]},"tagList":["admonition","configOptionRequirements","markdoc-example","table"],"title":"If and else tags","lastModified":"2026-10-01T23:00:57.000Z"}