diff --git a/docs/examples/index.md b/docs/examples/index.md index 7f5c2185..8d5e49d1 100644 --- a/docs/examples/index.md +++ b/docs/examples/index.md @@ -9,3 +9,4 @@ like to see here, please open [a GitHub discussion](https://github.com/denoland/fresh/discussions/new?category=ideas). - [Modifying the ``](./examples/modifying-the-head) +- [Setting the language](./examples/setting-the-language) diff --git a/docs/examples/setting-the-language.md b/docs/examples/setting-the-language.md new file mode 100644 index 00000000..cb091012 --- /dev/null +++ b/docs/examples/setting-the-language.md @@ -0,0 +1,52 @@ +--- +description: | + Set the lang attribute in the tag. +--- + +When you initialize a project with `deno run -A -r https://fresh.deno.dev`, +you'll end up with a `main.ts` like the following: + +``` +/// +/// +/// +/// +/// + +import { start } from "$fresh/server.ts"; +import manifest from "./fresh.gen.ts"; + +import twindPlugin from "$fresh/plugins/twind.ts"; +import twindConfig from "./twind.config.ts"; + +await start(manifest, { plugins: [twindPlugin(twindConfig)] }); +``` + +This is a great start if your site is in English, but let's say you want to +change the language, as per the `` tag. Then you'll need to do +something like this: + +``` +/// +/// +/// +/// +/// + +import { start } from "$fresh/server.ts"; +import manifest from "./fresh.gen.ts"; + +import twindPlugin from "$fresh/plugins/twind.ts"; +import twindConfig from "./twind.config.ts"; + +await start(manifest, { + plugins: [twindPlugin(twindConfig)], + render: (ctx, render) => { + ctx.lang = "de"; + render(); + }, +}); +``` + +If you're curious how this works, start by checking out `TemplateOptions` in +`render.ts`. diff --git a/docs/toc.json b/docs/toc.json index 5f75a76d..1db57f93 100644 --- a/docs/toc.json +++ b/docs/toc.json @@ -39,6 +39,9 @@ }, "examples": { "title": "Examples", - "pages": [["modifying-the-head", "Modifying the "]] + "pages": [ + ["modifying-the-head", "Modifying the "], + ["setting-the-language", "Setting the language"] + ] } }