Yet another Menu.item snippet question…

151 views
Skip to first unread message

Viktor Hedefalk

unread,
Oct 3, 2011, 6:36:40 AM10/3/11
to liftweb
I'm cleaning up some old stuff and I have this:

<lift:Menu.item name="LostPasswordApplicant">Glömt lösenord?</lift:Menu.item>

which I would like to replace with CSS bindings. But

<a class="lift:Menu.item?name=LostPasswordApplicant">Glömt lösenord?</a>

turns into two anchors:

<a href="/customer/lost_password"></a><a href="#">Glömt lösenord?</a>

which isn't what I want. This kindof works:

<span class="lift:Menu.item?name=LostPasswordApplicant">Glömt lösenord?</span>
->
<a href="/customer/lost_password"><span>Glömt lösenord?</span></a>

But I'd much rather drop the span due to styling issues.

I'm feeling thick as a brick again…

Thanks,
Viktor

Ján Raska

unread,
Oct 3, 2011, 7:48:04 AM10/3/11
to lif...@googlegroups.com
Hi Victor,

briefly looking at the code, Menu.item generates a link, using input NodeSeq as its content. However with CSS bindings, element containing a lift:Snippet class is also included in the input NodeSeq, as opposed to classical binding where <lift:Snippet> tag was excluded. 

I don't know if there is a way to ensure, only children are passed as input NodeSeq (if no, it'd be a nice feature I think), but supposing there is no other way, you could do it by making a wrapper snippet that'd look something like this:

import net.liftweb.util._
import Helpers._
import net.liftweb.builtin.snippet.Menu
import scala.xml._

class MyMenu 
{
def item =
{
  "*" #> ((ns:NodeSeq) => if(ns.isInstanceOf[Elem]) Menu.item(ns.asInstanceOf[Elem].child) else Menu.item(ns))
}
}


Hope it helps

Jan

Viktor Hedefalk

unread,
Oct 3, 2011, 8:40:06 AM10/3/11
to lif...@googlegroups.com
Hehe, definitely helped, I just grabbed your code :D

I'm thinking the difference you're describing is kind of an impedance
mismatch between css and old style binding and many of these built-in
snippets I guess are made for the old style of binding. Or maybe they
aren't _that_ many really. But then again, there might be some low
fruit making them easier to use out of the box for css binding…? I
mean for attracting newcomers if we say css binding is the way to go.
I guess this has already been discussed though :)

Thanks again!
Viktor

David Pollak

unread,
Oct 3, 2011, 12:34:48 PM10/3/11
to lif...@googlegroups.com
Please open a ticket that adds a flag to the Menu.item code that swallows the surrounding Elem.

Also, as a point of reference, you are not using CSS Selector Transforms, but instead, the invocation mechanism is Lift's "Designer Friendly" snippet invocation.  Designer friendly does not imply CSS Selector Transforms nor do CSS Selector Transforms imply Designer Friendly.  However, the two work best together.

--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code



--
Lift, the simply functional web framework http://liftweb.net

Ján Raska

unread,
Oct 3, 2011, 2:22:17 PM10/3/11
to lif...@googlegroups.com
Wouldn't it be possible to make this as a general feature for all snippets? So that I could add that flag anywhere and surrounding Elem would be swallowed before it is passed to the snippet method? I have quite many snippets with this flag coded in, so I think it would be handy for more people from Lift community.

Viktor Hedefalk

unread,
Oct 3, 2011, 3:43:40 PM10/3/11
to lif...@googlegroups.com
> Also, as a point of reference, you are not using CSS Selector Transforms,
> but instead, the invocation mechanism is Lift's "Designer Friendly" snippet
> invocation.  Designer friendly does not imply CSS Selector Transforms nor do
> CSS Selector Transforms imply Designer Friendly.  However, the two work best
> together.

Thanks for pointing this out. Of course they are not the same, I just
started using them simultaneously. I shouldn't be posting when my
brain has gone home :)

Ticket opened (I assigned it to DPP):
http://www.assembla.com/spaces/liftweb/tickets/1126-add-flag-to-menu-item-that-swallows-the-surrounding-elem-

Thanks,
Viktor

David Pollak

unread,
Oct 3, 2011, 6:22:06 PM10/3/11
to lif...@googlegroups.com
On Mon, Oct 3, 2011 at 11:22 AM, Ján Raska <ras...@gmail.com> wrote:
Wouldn't it be possible to make this as a general feature for all snippets? So that I could add that flag anywhere and surrounding Elem would be swallowed before it is passed to the snippet method? I have quite many snippets with this flag coded in, so I think it would be handy for more people from Lift community.

When it's your snippet, you control it, so making it general doesn't seem to be optimal to me, but if others want the flag, we can look into it.

Naftoli Gugenheim

unread,
Oct 10, 2011, 12:28:37 AM10/10/11
to lif...@googlegroups.com
I think some other forms of this issue have come up before. Perhaps it was forms and lift:loc? Jeppe, do you know what I'm thinking of?

Jeppe Nejsum Madsen

unread,
Oct 10, 2011, 10:16:50 AM10/10/11
to lif...@googlegroups.com
Naftoli Gugenheim <nafto...@gmail.com> writes:

> I think some other forms of this issue have come up before. Perhaps it was
> forms and lift:loc? Jeppe, do you know what I'm thinking of?


Maybe :-) Haven't read all the details in this thread.

I did add a method to the Loc snippet so you could write

<h2 class="lift:Loc.i">MyHeading</h2>

I.e. keep the h2 elem and use MyHeading as property key. This makes for
nice designer friendly localization.

I think the same could be used with the Menu snippet. But how to solve
the translation issue then?

One option could be to allow:

<a class="lift:Menu.item">LostPasswordApplicant</a>

which would add the correct href and translated menu name...

/Jeppe

Naftoli Gugenheim

unread,
Oct 10, 2011, 11:18:46 PM10/10/11
to lif...@googlegroups.com


> I think some other forms of this issue have come up before. Perhaps it was
> forms and lift:loc? Jeppe, do you know what I'm thinking of?


Maybe :-) Haven't read all the details in this thread.


Basically, a built in snippet that does what people expect when invoked with a <lift:XXX> tag, when invoked via designer-friendly produces an extra element, either adjacent to the element in the template or inside or around it.

Reply all
Reply to author
Forward
0 new messages