HiJoe
HiJoe7mo ago

Fresh - Page title to Layout

Hi, I have been browsing around the docs and also being new to JSX,I'm not sure what I look for. What I want todo is have a variable in the title tag of my _layout. So I can pass that var via the page.
7 Replies
marvinh.
marvinh.7mo ago
To set the document title from a route use the <Head> component. Example:
export default function MyPage() {
const world = "World!"

return <>
<Head>
<title>hello {world}</title>
</Head>
<h1>this is my page</h1>
</>
}
export default function MyPage() {
const world = "World!"

return <>
<Head>
<title>hello {world}</title>
</Head>
<h1>this is my page</h1>
</>
}
See https://fresh.deno.dev/docs/examples/modifying-the-head
HiJoe
HiJoe7mo ago
Right, I gave this as like recognizable example. I should have been more clear but it applies to non-head things
marvinh.
marvinh.7mo ago
In that case, what do you mean with "title tag" instead?
HiJoe
HiJoe7mo ago
This was a example. So it could also be a other part of the layout that expects per route values
marvinh.
marvinh.7mo ago
Right, I'm admittedly having trouble understanding what you're trying to do. Maybe you can rephrase what you're looking for?
HiJoe
HiJoe7mo ago
I have a section in my layout that depends on per route data. So like a head tag, I have a section within the layout that expects data from the Page (route). This is not a real example but Ill try to illustrate it. Layout
<head>
<title>{from_page: title} - John Doe Company</title>
</head>
<body>
<navbar />
<welcome />
<main>
<sidebar />
<section>
// Page content (<Component />)
</section>
<aside>
<p>Info 1: {from_page: info_a}</p>
</aside>
</main>
</body>
<head>
<title>{from_page: title} - John Doe Company</title>
</head>
<body>
<navbar />
<welcome />
<main>
<sidebar />
<section>
// Page content (<Component />)
</section>
<aside>
<p>Info 1: {from_page: info_a}</p>
</aside>
</main>
</body>
Page:
// title = 'Page'
// info_a = 'Something page related'
export default function Home() {
return (
<>
Page Content
</>
);
}
// title = 'Page'
// info_a = 'Something page related'
export default function Home() {
return (
<>
Page Content
</>
);
}
So title and info_a are defined within the page and should be rendered within the layout Hopefully that explains what I'm trying todo In "tradional" like tempalting engine it is often called blocks or sections and sometimes slots
MaDsEn
MaDsEn7mo ago
It looks like you're trying to dynamically populate certain elements in your layout based on route-specific data??. You might be able to achieve this using props
More Posts
When I use deno run I get this error: error : Permission denied (os error 13)When I use deno run I get this error: error : Permission denied (os error 13) (for '/Users/apple/LibAxios HttpsProxyAgentHello, I tryed to search but found nothing. I'm using axios with httpProxyAgent to proxy my outgoingGet input from an island, make calculus then render ?I have a route with 2 islands inside - one to get input from user - one to render data Once I've goHow can I create a seqential deno task to pass args to child task?Hi, I read the docs and created tasks in `deno.json` like this. https://docs.deno.com/runtime/manualUsing SCSS with FreshHi, I'm starting to get into Fresh for building simple static websites. Right now I want to use my Has anyone used React Material UI with Deno Fresh? Is this possible and also what are the componenetHas anyone used React Material UI with Deno Fresh? Is this possible and also what are the componenetJSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements'I have a core program, and from that I have auxiliary components: test, web app, cli app. Initially Using Deno.Command to run tailwindcss with watch flag not workingIf I do `new Deno.Command(Deno.execPath(), {args:["run", "-A", "npm:tailwindcss", "-i", "./styles.csESBuild SASS PluginHey, I have developed this Plugin: https://github.com/DenoPlayground/esbuild-plugin-sass But I havCan't spawn a shell properly using Deno!```ts const bash = (() => { const bashProc = spawn("bash"); bashProc.stdout.on("data", (data: s