Ok, I got this working, with 1.1-M8 using S.render.
// A node which embeds our 404 template (e.g. 404.html)
val notFoundNode =
<lift:embed what="404" />
// Catch 404s
LiftRules.uriNotFound.prepend {
case (req, _) => XhtmlTemplateResponse(notFoundNode, 404)
}
// If you're using a sitemap, make sure you have a catch-all item,
e.g
// Menu(Loc("Catchall", Pair(Nil, true), "", Hidden :: Nil)) ::
using this object:
object XhtmlTemplateResponse extends HeaderStuff {
def apply(nodeToRender: Node, statusCode: Int): LiftResponse = {
val renderedNode = S.render(nodeToRender,
S.request.get.request).first
new XhtmlResponse(renderedNode, Empty, headers, cookies,
statusCode, false)
}
}
I think the wiki page:
http://wiki.liftweb.net/index.php/Setting_up_a_custom_404_page
should be updated. The current code hides the 404 status code and
changes the url.
I'd offer to write the new wiki page - is there a way for me to get an
account on that wiki - or is it just for contributors?
- Alex
On Dec 29, 1:20 pm, Alex Black <[email protected]> wrote:
> > If you want to display the contents of your 404.html, checkout
> > NodeResponse... just load up your template using the template helpers (this
> > will give you NodeSeq) and then you can present that back to the user. Job
> > done.
>
> I am familiar with NodeResponse and its subclasses. I've used them in
> our REST api. But, what I can't figure out, is how to use them in
> conjuction with the templating engine as you seem to be alluding to
> (with the template helpers).
>
> Can you point me in the right direction? I am going to try switching
> to M8 and then using S.render like this:
>
> val node404 = <lift:surround with="default" at="content">
> <h1>Not Found</h1>
> </lift:surround>
>
> LiftRules.uriNotFound.prepend {
> case (req, _) => XhtmlResponse(S.render(node404, req), _,
> headers, cookies, 404, false)
> }
>
>
>
> > Cheers, Tim
>
> > On 29 Dec 2009, at 15:23, Alex Black wrote:
>
> > > But of course RewriteResponse is not a LiftResponse. Whats the best
> > > way to do this? Basically I've got a template called 404.html which
> > > I'd like to display whenever there is a 404.
>
> > > I Just thought of something, perhaps I could add a RewriteRule that
> > > matches everything?
--
You received this message because you are subscribed to the Google Groups
"Lift" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en.