\n\n\n```\n\n \n \n\nTo use nested 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

Full Nested Content: {JSON.stringify($content.fullNestedContent)}

\n

Partial Nested Value: {$content.partialNestedContent}

\n
\n```\n\n
\n \n\nTo use nested 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 NestComponent: FC = () => {\n const { fullNestedContent, partialNestedContent } = useIntlayer(\n \"key_of_my_second_dictionary\"\n );\n\n return (\n
\n

Full Nested Content: {JSON.stringify(fullNestedContent)}

\n

Partial Nested Value: {partialNestedContent}

\n
\n );\n};\n\nexport default NestComponent;\n```\n\n
\n \n\nTo use nested 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 NestComponent: Component = () => {\n const { fullNestedContent, partialNestedContent } = useIntlayer(\n \"key_of_my_second_dictionary\"\n );\n\n return (\n
\n

Full Nested Content: {JSON.stringify(fullNestedContent)}

\n

Partial Nested Value: {partialNestedContent}

\n
\n );\n};\n\nexport default NestComponent;\n```\n\n
\n \n\nTo use nested 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-nest\",\n template: `\n
\n

\n Full Nested Content: {{ JSON.stringify(content().fullNestedContent) }}\n

\n

Partial Nested Value: {{ content().partialNestedContent }}

\n
\n `,\n})\nexport class NestComponent {\n content = useIntlayer(\"key_of_my_second_dictionary\");\n JSON = JSON;\n}\n```\n\n
\n \n\nTo use nested 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(\"key_of_my_second_dictionary\").onChange(\n (newContent) => {\n document.getElementById(\"nested\")!.textContent =\n newContent.partialNestedContent;\n }\n);\n\n// Initial render\ndocument.getElementById(\"nested\")!.textContent = content.partialNestedContent;\n```\n\n \n\n\n## Additional Resources\n\nFor more detailed information on configuration and usage, refer to the following resources:\n\n- [Intlayer CLI Documentation](/doc/concept/cli)\n- [React Intlayer Documentation](/doc/environment/create-react-app)\n- [Next Intlayer Documentation](/doc/environment/nextjs/15)\n\nThese resources provide further insights into the setup and usage of Intlayer in different environments and with various frameworks.\n","description":"Learn how to use content nesting in Intlayer to reuse and structure your multilingual content efficiently. Follow this documentation to implement nesting seamlessly in your project.","url":"https://intlayer.org/doc/concept/content/nesting","datePublished":"2025-02-07","dateModified":"2025-06-29","version":"5.5.10","keywords":"Nesting, Content Reusability, Documentation, Intlayer, Next.js, JavaScript, React","license":"https://raw.githubusercontent.com/aymericzip/intlayer/refs/heads/main/LICENSE","audience":{"@type":"Audience","audienceType":"Developers, Content Managers"}}
    Author:
    Creation:2025-02-07Last update:2025-06-29

    Nesting / Sub Content Referencing

    How Nesting Works

    In Intlayer, nesting is achieved through the nest function, which allows you to reference and reuse content from another dictionary. Instead of duplicating content, you can point to an existing content module by its key.

    Setting Up Nesting

    To set up nesting in your Intlayer project, you first define the base content that you wish to reuse. Then, in a separate content module, you use the nest function to import that content.

    Base Dictionary

    Below is an example of a base dictionary to nest in another dictionary:

    firstDictionary.content.ts
    import { type Dictionary } from "intlayer";
    
    const firstDictionary = {
      key: "key_of_my_first_dictionary",
      content: {
        content: "content",
        subContent: {
          contentNumber: 0,
          contentString: "string",
        },
      },
    } satisfies Dictionary;
    
    export default firstDictionary;

    Referencing with Nest

    Now, create another content module that uses the nest function to reference the above content. You can reference the entire content or a specific nested value:

    secondDictionary.content.ts
    import { nest, type Dictionary } from "intlayer";
    
    const myNestingContent = {
      key: "key_of_my_second_dictionary",
      content: {
        // References the entire dictionary:
        fullNestedContent: nest("key_of_my_first_dictionary"),
        // References a specific nested value:
        partialNestedContent: nest(
          "key_of_my_first_dictionary",
          "subContent.contentNumber"
        ),
      },
    } satisfies Dictionary;
    
    export default myNestingContent;

    As second parameter, you can specify a path to a nested value within that content. When no path is provided, the entire content of the referenced dictionary is returned.

    Using Nesting

    To use nested content in a React component, leverage the useIntlayer hook from the react-intlayer package. This hook retrieves the correct content based on the specified key. Here's an example of how to use it:

    **/*.tsx
    import type { FC } from "react";
    import { useIntlayer } from "react-intlayer";
    
    const NestComponent: FC = () => {
    const { fullNestedContent, partialNestedContent } = useIntlayer(
      "key_of_my_second_dictionary"
    );
    
    return (
      <div>
        <p>Full Nested Content: {JSON.stringify(fullNestedContent)}</p>
        <p>Partial Nested Value: {partialNestedContent}</p>
      </div>
    );
    };
    
    export default NestComponent;

    Additional Resources

    For more detailed information on configuration and usage, refer to the following resources:

    These resources provide further insights into the setup and usage of Intlayer in different environments and with various frameworks.