\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## 在 React Intlayer 中使用嵌套\n\n要在 React 组件中使用嵌套内容,可以利用 `react-intlayer` 包中的 `useIntlayer` 钩子。此钩子根据指定的键检索正确的内容。以下是如何使用它的示例:\n\n```tsx fileName=\"**/*.tsx\" codeFormat={[\"typescript\", \"esm\"]}\nimport type { FC } from \"react\";\nimport { useIntlayer } from \"react-intlayer\";\n\nconst NestComponent: FC = () => {\n const { fullNestedContent, partialNestedContent } = useIntlayer(\n \"key_of_my_second_dictionary\"\n );\n\n return (\n
\n

\n Full Nested Content: {JSON.stringify(fullNestedContent)}\n {/* 输出: {\"content\": \"content\", \"subContent\": {\"contentNumber\": 0, \"contentString\": \"string\"}} */}\n

\n

\n Partial Nested Value: {partialNestedContent}\n {/* 输出: 0 */}\n

\n
\n );\n};\n\nexport default NestComponent;\n```\n\n## 其他资源\n\n有关配置和使用的更多详细信息,请参考以下资源:\n\n- [Intlayer CLI 文档](/zh/doc/concept/cli)\n- [React Intlayer 文档](/zh/doc/environment/create-react-app)\n- [Next Intlayer 文档](/zh/doc/environment/nextjs/15)\n\n这些资源提供了在不同环境和各种框架中设置和使用 Intlayer 的更多见解。\n","description":"了解如何在Intlayer中使用内容嵌套,以高效地重用和构造您的多语言内容。按照本文档的步骤无缝实施嵌套。","url":"https://intlayer.org/zh/doc/concept/content/nesting","datePublished":"2025-02-07","dateModified":"2025-06-29","keywords":"Nesting, 内容重用, 文档, Intlayer, Next.js, JavaScript, React","license":"https://raw.githubusercontent.com/aymericzip/intlayer/refs/heads/main/LICENSE","audience":{"@type":"Audience","audienceType":"开发者,内容经理"}}
    作者:
    Creation:2025-02-07Last update:2025-06-29

    嵌套 / 子内容引用

    嵌套如何工作

    在 Intlayer 中,嵌套是通过 nest 函数实现的,它允许您引用和重用来自另一个字典的内容。与其重复内容,不如通过其键指向现有的内容模块。

    设置嵌套

    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;

    在 React Intlayer 中使用嵌套

    要在 React 组件中使用嵌套内容,可以利用 react-intlayer 包中的 useIntlayer 钩子。此钩子根据指定的键检索正确的内容。以下是如何使用它的示例:

    **/*.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)}
            {/* 输出: {"content": "content", "subContent": {"contentNumber": 0, "contentString": "string"}} */}
          </p>
          <p>
            Partial Nested Value: {partialNestedContent}
            {/* 输出: 0 */}
          </p>
        </div>
      );
    };
    
    export default NestComponent;

    其他资源

    有关配置和使用的更多详细信息,请参考以下资源:

    这些资源提供了在不同环境和各种框架中设置和使用 Intlayer 的更多见解。