Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
chasegiunta committed Dec 20, 2024
1 parent 130bd65 commit fe4d7d2
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ Every page in your javascript application is backed by a Twig template which ret
body: post.body
}) %}
{# Use the Inertia variable to return the Page component to render, and the props to pass down #}
{# Use the inertia variable to define the Page component to render and props to pass #}
{{ inertia('Posts/Index', { posts: posts }) }}
```

Note: templates are passed `element` variables automatically when a request is matched to an element. If you want to pass the element as a prop automatically to your page component, set the `injectElementAsProp` configuration to `true`.

## Shared Data

Shared data will automatically be passed as props to your application, sparing you the cumbersome tasks of redefining the same prop data in every page response.
Expand Down Expand Up @@ -66,6 +68,33 @@ Create a `shared.twig` at the root of your `/templates` directory, and use the `
{{ inertiaShare(shareProps) }}
```

## Saving Data

Craft CMS does not use traditional POST, PUT, PATCH, and DELETE requests for saving data, and instead uses the `action` parameter to hit various internal Craft controllers. This means saving data to Craft CMS data is a little different than what is expected in a traditional Inertia application.

```js
const form = useForm({
sectionId: 1,
typeId: 2,
CRAFT_CSRF_TOKEN: csrf.value,
action: "entries/save-entry",
title: "My New Post",
fields: {
customField: "My Custom Field Value",
},
});

const saveEntry = () => {
// Don't specify a POST url, as we're using the action parameter
form.post("", {
// Force the request to use form data in order for Craft to process the request
forceFormData: true,
});
};
```

We hope to simplify this boilerplate for saving data by final 1.0.0 release.

## Configuration

Create an `inertia.php` file in your Craft `/config` directory. Shown are the default values:
Expand Down

0 comments on commit fe4d7d2

Please sign in to comment.