Skip to content

Latest commit

 

History

History
52 lines (41 loc) · 1.38 KB

File metadata and controls

52 lines (41 loc) · 1.38 KB
description Set the lang attribute in the <html> tag.

When you initialize a project with deno run -A -r https://usefresh.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.