<a href={myLoc.createDefaultLink}>Foo</a>

In Scala, if the attribute is an Option[NodeSeq] and it is None, the
attribute will not be included where if it's Some(Text("/foo/bar")) it will
be included.  Thus the choice of Option rather than Box and the choice of
NodeSeq rather than String.

In terms of your code:

(for {
  loc <- SiteMap.findLoc("Login")
  path <- loc.createDefaultPath
 } yield <a href={path}>Login</a>) openOr NodeSeq.Empty



On Tue, Jan 26, 2010 at 2:29 AM, Adam Warski <a...@warski.org> wrote:

> Hello,
>
> I'm having some trouble generating a link basing on a Loc.
> My original use-case is to redirect the user to a  login page if the user
> is not logged in. I found a wiki on this and it says there to simply
> redirect to "/user_mgt/login", however I think it would be much nicer if I
> could generate the link basing on looking up the right Loc.
>
> However having the Loc I can only generate a NodeSeq, not a plain String.
>
> So the solution would be to add a method into the Loc trait parallel to
> this one:
>
> def createDefaultLink: Option[NodeSeq] = currentValue.flatMap(p =>
> link.createLink(p)).toOption
>
> which would be:
>
> def createDefaultPath: Option[String] = currentValue.flatMap(p =>
> link.createPath(p)).toOption
>
> (btw., why is it Option here, not Box?)
>
> Then generating a link to the login page would simply be:
>
> SiteMap.findLoc("Login").open_!.createDefaultPath
>
> --
> Adam Warski
> http://www.warski.org
> http://www.softwaremill.eu
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Lift" group.
> To post to this group, send email to lift...@googlegroups.com.
> To unsubscribe from this group, send email to
> liftweb+unsubscr...@googlegroups.com<liftweb%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/liftweb?hl=en.
>
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

-- 
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.

Reply via email to