#is it possible to get the collection on server actions like i have a .yaml file which holds the "To

1 messages · Page 1 of 1 (latest)

austere sail
#

How can i get the daata on server side they are in data/singletons/email.yaml file

heady frigateBOT
#

Hi @austere sail. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Yes, it is possible to access collection data from YAML files in server actions in Astro. Based on the information provided in the knowledge sources, here's how you can achieve this:

  1. First, you'll need to set up YAML support in your Astro project. You can do this by installing and configuring the @rollup/plugin-yaml plugin as described in the Add YAML Support recipe.

  2. Once YAML support is set up, you can use the Content Collections API to define and query your YAML content. In your src/content.config.ts file, you can define a collection that uses the file() loader to load your YAML data:

import { defineCollection } from 'astro:content';
import { file } from 'astro/loaders';

const email = defineCollection({
  loader: file('src/data/singletons/email.yaml'),
  schema: /* define your schema here */
});

export const collections = { email };
  1. In your server action, you can then use the getEntry() function from astro:content to retrieve the data from your YAML file. Here's an example of how you might do this in a server action:
import { defineAction } from 'astro:actions';
import { getEntry } from 'astro:content';

export const server = {
  getEmailData: defineAction({
    async handler() {
      const emailData = await getEntry('email', 'email');
      return emailData.data;
    }
  })
};

This approach allows you to access your YAML data on the server side within your actions. Remember to adjust the file paths and collection names to match your project structure.

#

For more detailed information on working with Content Collections, you can refer to the Content Collections documentation.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: