Logo
  1. Docs
  2. Hydrogen Theme Customizer

Integrating Weaverse with existing Hydrogen projects

Introduction

If you're keen on integrating Weaverse into your existing Hydrogen project or simply curious about Weaverse's inner workings, you're in the right place. This guide will walk you through integrating Weaverse SDKs & Theme Customizer using a clean demo-store sample from Shopify Hydrogen. Before diving in, ensure your Hydrogen project is ready in your preferred IDE.

1. Installing the Weaverse SDK:

Kickstart by integrating the Weaverse SDK library for Hydrogen:

npm install @weaverse/hydrogen

2. Scaffolding the Weaverse Directory:

Create a weaverse directory within your Hydrogen app folder. This will house essential files to establish a Weaverse Client Provider, register Section Components, and define theme schema settings. Simply copy the following files into your app/weaverse directory:

  • File: app/weaverse/components.ts

WEAVERSE_EMBEDED_CODE

  • File app/weaverse/theme-schema.ts

WEAVERSE_EMBEDED_CODE

  • File app/weaverse/client.ts

WEAVERSE_EMBEDED_CODE

3. Integrating Weaverse Client into Hydrogen's Server Context

Navigate to the server.ts file in your Hydrogen project. Incorporate the weaverse client into the getLoadContext function as illustrated below:

WEAVERSE_EMBEDED_CODE

4. Incorporating Weaverse Global Theme Settings

The Global Theme Settings feature facilitates theme setting sharing across all routes, akin to Shopify's Online Store Theme Customizer. To leverage this, open the root.tsx file and integrate the weaverseTheme data properties into the loader function. Here's a comprehensive loader snippet:

WEAVERSE_EMBEDED_CODE

Notice the added here:

weaverseTheme: await context.weaverse.loadThemeSettings(),

Additionally, the App component needs to be wrapped with the withWeaverse API.

WEAVERSE_EMBEDED_CODE

5. Updating Routes for Weaverse Content Rendering

To effectively display content managed by Weaverse, it's essential to incorporate the <WeaverseContent /> component within the desired routes. This component is a core part of Weaverse's functionality, ensuring that your theme customizations are reflected accurately in the live project.

For instance, consider the app/routes/($locale)._index.tsx file:

WEAVERSE_EMBEDED_CODE

Key Takeaway:
While it's possible to render the <WeaverseContent /> component alongside other components, it's recommended to position the WeaverseContent at the topmost level of the route hierarchy. This ensures that Weaverse's configurations and customizations are prioritized and rendered accurately throughout your project.

6. Incorporating the Section Component

Main Component:

WEAVERSE_EMBEDED_CODE

Video Section:

For a more specific example, let's explore how to add a Video section:

WEAVERSE_EMBEDED_CODE

Registering the Sections:

After creating the Main and Video sections, you need to register them. Update the app/weaverse/components.ts file as follows:

WEAVERSE_EMBEDED_CODE

7. What's Next?

Congratulations! You've now grasped how to integrate Weaverse into your existing Hydrogen project. Perhaps you've also gained insights into the mechanics of Weaverse's Hydrogen SDKs. To delve further, our upcoming article will guide you through defining Section Input settings, enabling sections to be tailored via the Weaverse Hydrogen Theme Customizer. Stay tuned!