1

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.

akonsu
  • 28,824
  • 33
  • 119
  • 194
  • Any reason #{...} interpolation won't work? – Michael Snoyman Sep 07 '11 at 16:53
  • would you please give me an example how to use it? – akonsu Sep 07 '11 at 17:00
  • You said "some HTML contents." I'm not quite sure what you mean, but if you had a variable called `foo` of type `Html`, then you could just replace ???? with `#{foo}`. – Michael Snoyman Sep 07 '11 at 17:34
  • to render my variable in default-layout.hamlet I need to define this variable in my foundation type's defaultLayout. if I do that, interpolation works. I am looking for a way to define this variable in my handler and still use it in the default-layout.hamlet. I would like to have the common HTML structure in the default-layout.hamlet, which handlers will fill in as they need. – akonsu Sep 07 '11 at 18:03
  • Why can't you define the variable inside the defaultLayout function? I'm not entirely certain what you're going for here, can you perhaps expand your question to make it clearer? – Michael Snoyman Sep 08 '11 at 05:27
  • as I said, I was looking for a way to render HTML from my handlers in several different places inside the default template. I have updated the question. I am not a native english speaker, sorry if I am not clear... – akonsu Sep 08 '11 at 12:55

1 Answers1

1

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.

Michael Snoyman
  • 31,100
  • 3
  • 48
  • 77