need to render several html snippets in different places inside a hamlet template

StackOverflow https://stackoverflow.com/questions/7337341

  •  27-10-2019
  •  | 
  •  

Pergunta

in my default-layout.hamlet:

!!!
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>#{pageTitle pc}
    ^{pageHead pc}
  <body>
    <div id="main">
      <div id="header">
        ????
      <div id="content">
        ^{pageBody pc}

from a handler function, I need to replace the ???? above with some HTML contents.

how is this done?

thanks for any input.

EDIT:

I am looking for functionality similar to, for example, django's template blocks. I can define a block inside a template and the handler that uses this template for rendering, can fill in the template's blocks with the needed contents. Right now, yesod has effectively a single block in a template's body. that "defined" by the call ^{pageBody pc}. I know I can build up the output generated by pageBody any way I want using addWidget etc., but right now I will need to output my <div id="header"> and <div id="content"> too and I want to avoid that because all my handlers will have to output these div's to have the same markup structure in all the pages.

Foi útil?

Solução

I think the answer is to define a function besides defaultLayout. The only thing that's magical about defaultLayout is that subsites (e.g., auth) and error messages use it by default. But you could define a "myDefaultLayout" that takes the other pieces of content you want. You could even define a helper function that wraps up the extra blocks into a single block and then passes that to defaultLayout.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top