\n\n\n```\n\n \n \n\nTo utilize conditional content in Svelte components, retrieve it via the `useIntlayer` hook. The store is accessed with `$`. Here's an example:\n\n```svelte fileName=\"**/*.svelte\"\n\n\n
\n

{$content.myCondition(true)}

\n

{$content.myCondition(false)}

\n
\n```\n\n
\n \n\nTo utilize conditional content in Preact components, retrieve it via the `useIntlayer` hook. Here's an example:\n\n```tsx fileName=\"**/*.tsx\" codeFormat={[\"typescript\", \"esm\"]}\nimport type { FC } from \"preact\";\nimport { useIntlayer } from \"preact-intlayer\";\n\nconst ConditionalComponent: FC = () => {\n const { myCondition } = useIntlayer(\"my_key\");\n\n return (\n
\n

{myCondition(true)}

\n

{myCondition(false)}

\n
\n );\n};\n\nexport default ConditionalComponent;\n```\n\n
\n \n\nTo utilize conditional content in SolidJS components, retrieve it via the `useIntlayer` hook. Here's an example:\n\n```tsx fileName=\"**/*.tsx\" codeFormat={[\"typescript\", \"esm\"]}\nimport type { Component } from \"solid-js\";\nimport { useIntlayer } from \"solid-intlayer\";\n\nconst ConditionalComponent: Component = () => {\n const { myCondition } = useIntlayer(\"my_key\");\n\n return (\n
\n

{myCondition(true)}

\n

{myCondition(false)}

\n
\n );\n};\n\nexport default ConditionalComponent;\n```\n\n
\n \n\nTo utilize conditional content in Angular components, retrieve it via the `useIntlayer` hook. Here's an example:\n\n```typescript fileName=\"app.component.ts\" codeFormat=\"typescript\"\nimport { Component } from \"@angular/core\";\nimport { useIntlayer } from \"angular-intlayer\";\n\n@Component({\n selector: \"app-conditional\",\n template: `\n
\n

{{ content().myCondition(true) }}

\n

{{ content().myCondition(false) }}

\n
\n `,\n})\nexport class ConditionalComponent {\n content = useIntlayer(\"my_key\");\n}\n```\n\n
\n \n\nTo utilize conditional content with `vanilla-intlayer`, retrieve it via the `useIntlayer` hook. Here's an example:\n\n```typescript fileName=\"**/*.ts\" codeFormat={[\"typescript\", \"esm\"]}\nimport { installIntlayer, useIntlayer } from \"vanilla-intlayer\";\n\ninstallIntlayer();\n\nconst content = useIntlayer(\"my_key\").onChange((newContent) => {\n document.getElementById(\"true-content\")!.textContent =\n newContent.myCondition(true);\n document.getElementById(\"false-content\")!.textContent =\n newContent.myCondition(false);\n});\n\n// Initial render\ndocument.getElementById(\"true-content\")!.textContent =\n content.myCondition(true);\ndocument.getElementById(\"false-content\")!.textContent =\n content.myCondition(false);\n```\n\n \n\n\n## Zusätzliche Ressourcen\n\nFür detailliertere Informationen zur Konfiguration und Nutzung finden Sie in den folgenden Ressourcen:\n\n- [Intlayer CLI Dokumentation](/de/doc/concept/cli)\n- [React Intlayer Dokumentation](/de/doc/environment/create-react-app)\n- [Next Intlayer Dokumentation](/de/doc/environment/nextjs/15)\n\nDiese Ressourcen bieten weitere Einblicke in die Einrichtung und Nutzung von Intlayer in verschiedenen Umgebungen und Frameworks.\n","description":"Erfahren Sie, wie Sie bedingte Inhalte in Intlayer nutzen können, um Inhalte dynamisch basierend auf bestimmten Bedingungen anzuzeigen. Folgen Sie dieser Dokumentation, um Bedingungen effizient in Ihr Projekt zu integrieren.","url":"https://intlayer.org/de/doc/concept/content/condition","datePublished":"2025-02-07","dateModified":"2025-06-29","keywords":"Bedingte Inhalte, Dynamische Darstellung, Dokumentation, Intlayer, Next.js, JavaScript, React","license":"https://raw.githubusercontent.com/aymericzip/intlayer/refs/heads/main/LICENSE","audience":{"@type":"Audience","audienceType":"Entwickler, Inhaltsmanager"}}
    Autor:
    Erstellung:2025-02-07Letzte Aktualisierung:2025-06-29

    Bedingter Inhalt / Bedingung in Intlayer

    Wie Bedingung funktioniert

    In Intlayer wird bedingter Inhalt durch die cond-Funktion erreicht, die spezifische Bedingungen (typischerweise boolesche Werte) ihren entsprechenden Inhalten zuordnet. Dieser Ansatz ermöglicht es Ihnen, Inhalte dynamisch basierend auf einer gegebenen Bedingung auszuwählen. Wenn es mit React Intlayer oder Next Intlayer integriert ist, wird der entsprechende Inhalt automatisch gemäß der zur Laufzeit bereitgestellten Bedingung ausgewählt.

    Einrichten von bedingtem Inhalt

    Um bedingten Inhalt in Ihrem Intlayer-Projekt einzurichten, erstellen Sie ein Inhaltsmodul, das Ihre bedingten Definitionen enthält. Nachfolgend finden Sie Beispiele in verschiedenen Formaten.

    **/*.content.ts
    import { cond, type Dictionary } from "intlayer";
    
    const myConditionalContent = {
      key: "my_key",
      content: {
        myCondition: cond({
          true: "mein Inhalt, wenn es wahr ist",
          false: "mein Inhalt, wenn es falsch ist",
          fallback: "mein Inhalt, wenn die Bedingung fehlschlägt", // Optional
        }),
      },
    } satisfies Dictionary;
    
    export default myConditionalContent;
    Wenn kein Fallback deklariert ist, wird der zuletzt deklarierte Schlüssel als Fallback verwendet, falls die Bedingung nicht erfüllt ist.

    Verwendung von bedingtem Inhalt mit React Intlayer

    To utilize conditional content within a React component, import and use the useIntlayer hook from the react-intlayer package. This hook fetches the content for the specified key and allows you to pass in a condition to select the appropriate output.

    **/*.tsx
    import type { FC } from "react";
    import { useIntlayer } from "react-intlayer";
    
    const ConditionalComponent: FC = () => {
    const { myCondition } = useIntlayer("my_key");
    
    return (
      <div>
        <p>
          {
            /* Output: my content when it's true */
            myCondition(true)
          }
        </p>
        <p>
          {
            /* Output: my content when it's false */
            myCondition(false)
          }
        </p>
        <p>
          {
            /* Output: my content when the condition fails */
            myCondition("")
          }
        </p>
        <p>
          {
            /* Output: my content when the condition fails */
            myCondition(undefined)
          }
        </p>
      </div>
    );
    };
    
    export default ConditionalComponent;

    Zusätzliche Ressourcen

    Für detailliertere Informationen zur Konfiguration und Nutzung finden Sie in den folgenden Ressourcen:

    Diese Ressourcen bieten weitere Einblicke in die Einrichtung und Nutzung von Intlayer in verschiedenen Umgebungen und Frameworks.