--- description: | Modify content by passing state between AppWrapper/Layout and routes. --- It's a common requirement for specific pages to need changes to content inside the `` tag. - Setting the document title using `` - Specifying page metadata using `<meta>` - Linking to resources like stylesheets using `<link>` - Including third-party JavaScript code using `<script>` ## App Wrapper with State The recommended way to modify content in `<head>` is to use an app wrapper in combination with `Context.state`. ### 1. State The first step can be to define the possible state available on `Context`. In this example, the `State` is very general to allow very flexible usage. ```ts util.ts import { createDefine } from "fresh"; import type { JSX } from "preact"; export interface State { title?: string; metas?: JSX.IntrinsicElements["meta"][]; links?: JSX.IntrinsicElements["link"][]; scripts?: JSX.IntrinsicElements["script"][]; } export const define = createDefine<State>(); ``` ### 2. App wrapper After defining the State, create the App Wrapper to render the HTML with the provided State. ```tsx routes/_app.tsx import { define } from "../util.ts"; export default define.page(function AppWrapper(ctx) { const { title, links, metas, scripts } = ctx.state; return ( <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>{title ? `${title} | My App` : "My App"} {metas?.map((attrs, i) => )} {links?.map((attrs, i) => )} {scripts?.map((attrs, i) =>