How do I implement layouts other than defaultLayout?

245 views
Skip to first unread message

Si

unread,
Nov 2, 2012, 10:35:03 AM11/2/12
to yeso...@googlegroups.com
I just tried to duplicate defaultLayout as "adminLayout" in a Handler module, but found the following issues:

Not in scope: data constructor `LogoutR'
    In the result of the splice:
      $(hamletFile "templates/default-layout-wrapper.hamlet")

Not in scope: `appExtra'
    In the result of the splice:
      $(hamletFile "templates/default-layout-wrapper.hamlet")

The code duplicated from defaultLayout, and the templates referenced, have only minor code changes from the standard scaffolding versions. The LogoutR refers to the Auth subsite logout route, and the appExtra is due to the scaffold inclusion of a copyright setting.

Other "top level" routes are generated correctly, and "pages" work generally through the new layout, so I guess I need to do something more to get back the extra context needed for finding those functions in scope (as if it were declared like the Yesod App instance).

What's the recommended way to create layouts other than the defaultLayout? Am I on the wrong track, or just missing something?

Thanks,
Si

Michael Snoyman

unread,
Nov 3, 2012, 11:46:51 AM11/3/12
to yeso...@googlegroups.com

I think the issue is just one of missing imports. LogoutR comes from Yesod.Auth and appExtra from Foundation.hs (I think).

Si

unread,
Nov 3, 2012, 12:41:04 PM11/3/12
to yeso...@googlegroups.com, mic...@snoyman.com
You're quite right! Fixed with:

import Yesod.Auth (Route(LogoutR))
import Yesod.Default.Config (appExtra)

This will enable me to start work on the other roles in my system. Thanks :)

Si

unread,
Nov 12, 2012, 12:25:20 PM11/12/12
to yeso...@googlegroups.com, mic...@snoyman.com
Hiya,

It might be easiest to start with your adminLayout function in a handler, then move it out to a separate module, adding the other imports needed.

I use a Layout module that I include in Import.hs for convenience, but that requires you to work around cyclic dependencies when it's more fruitful to get your layout function working first.

If you clone the defaultLayout, and have scaffold templating, you'll certainly need:

import Yesod.Default.Config (appExtra)

I think the rest will be provided by the standard Import.hs import.

What error are you seeing?

Si

On Monday, November 12, 2012 6:05:54 PM UTC+1, Christian Laustsen wrote:
Hi, 
terribly sorry to rip open this thread, but I'm struggling with a doing an adminLayout also and was wondering how you went about it?

Christian Laustsen

unread,
Nov 12, 2012, 12:34:39 PM11/12/12
to yeso...@googlegroups.com, mic...@snoyman.com
Wow, seemed like import Yesod.Default.Config (appExtra) was all i was missing :)

was staring myself blind at this, thanks so much for taking time to answer!

sincerely Christian

Si

unread,
Nov 12, 2012, 12:38:39 PM11/12/12
to yeso...@googlegroups.com
Ha! Very much like the issue I had at the time then.

I convinced myself somehow that "magic" was happening, perhaps related to it being a class instance function, and overlooked the obvious.
Reply all
Reply to author
Forward
0 new messages