How do I implement layouts other than defaultLayout?

已查看 245 次
跳至第一个未读帖子

Si

未读,
2012年11月2日 10:35:032012/11/2
收件人 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

未读,
2012年11月3日 11:46:512012/11/3
收件人 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

未读,
2012年11月3日 12:41:042012/11/3
收件人 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

未读,
2012年11月12日 12:25:202012/11/12
收件人 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

未读,
2012年11月12日 12:34:392012/11/12
收件人 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

未读,
2012年11月12日 12:38:392012/11/12
收件人 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.
回复全部
回复作者
转发
0 个新帖子