docs: add "setting the language" example (#1265)
This commit is contained in:
@@ -9,3 +9,4 @@ like to see here, please open
|
||||
[a GitHub discussion](https://github.com/denoland/fresh/discussions/new?category=ideas).
|
||||
|
||||
- [Modifying the `<head>`](./examples/modifying-the-head)
|
||||
- [Setting the language](./examples/setting-the-language)
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
---
|
||||
description: |
|
||||
Set the lang attribute in the <html> 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:
|
||||
|
||||
```
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
|
||||
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 `<html lang=asdf>` tag. Then you'll need to do
|
||||
something like this:
|
||||
|
||||
```
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
|
||||
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`.
|
||||
+4
-1
@@ -39,6 +39,9 @@
|
||||
},
|
||||
"examples": {
|
||||
"title": "Examples",
|
||||
"pages": [["modifying-the-head", "Modifying the <head>"]]
|
||||
"pages": [
|
||||
["modifying-the-head", "Modifying the <head>"],
|
||||
["setting-the-language", "Setting the language"]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user