D
Deno

help

Fresh - Page title to Layout

HHiJoe1/12/2024
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.
Mmarvinh.1/12/2024
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
HHiJoe1/12/2024
Right, I gave this as like recognizable example. I should have been more clear but it applies to non-head things
Mmarvinh.1/12/2024
In that case, what do you mean with "title tag" instead?
HHiJoe1/12/2024
This was a example. So it could also be a other part of the layout that expects per route values
Mmarvinh.1/12/2024
Right, I'm admittedly having trouble understanding what you're trying to do. Maybe you can rephrase what you're looking for?
HHiJoe1/12/2024
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
MMaDsEn1/14/2024
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

Looking for more? Join the community!

Recommended 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: sHow to optimize imports on deno deploy?I have a medium project (44 files) deployed on deno deploy, where works. But, I'm getting inconsistLSP complains about missing package mongodbVS Code keeps complaining about "uncached or missing npm package: mongodb". `Cache "npm:mongodb" andnode.js to Deno remix template migrationI would like to migrate one of the templates in remix from node.js to Deno. I am not sure how to do How to pass value from one form to another?I want to design a form which has two input text field. What users type in field 1 will be passed toHow to build a Response object with the 'url' property setWriting unit tests. Some functions parse Response objects. How do I create some where the `url` propWhy Deno is not a library?For example, I'd like to embed JavaScript (Deno) on FreeBasic or Rust to able Users to write JavaScr`deno cache` consistently failing with the same errorerror: error sending request for url (https://deno.land/std@0.152.0/http/negotiation.ts): dispatch tDoes fetch() support upgrading the connection to a websocket?What happens when `fetch()` gets the response ``` HTTP/1.1 101 Switching Protocols connection: upgrError: Not implemented: crypto.Sign``` Error: Not implemented: crypto.Sign at notImplemented (https://deno.land/std@0.177.1/node/_uHow can I access req object inside a render() function from fresh plugin?Is it possible?