Surround with not working when using ChooseTemplate for mobile

123 views
Skip to first unread message

Kevin

unread,
Oct 6, 2012, 3:17:48 PM10/6/12
to lif...@googlegroups.com
Hi there, I've created a fork of lift_25_sbt to show a problem I'm having where I use a snippet to choose either a normal template or a mobile phone template. The snippet is working, but the content is not being replace by pages with a surround.

Here is the fork: https://github.com/kevg/lift_25_sbt

And here is the diff: https://github.com/kevg/lift_25_sbt/commit/c8803daf95c6e007409de672e1dcb5231d97177a

I changed the default template to be the ChooseTemplate based on David's suggestion: https://groups.google.com/d/msg/liftweb/g1Co9wvvbBM/mpZymarR06AJ

<div class="lift:ChooseTemplate">
  <div id"normal" class="lift:embed?what=normal_template"></div>
  <div id="mobile" class="lift:embed?what=mobile_template"></div>
</div>

When I run the code, I get "The main content will get bound here" instead of the content of the page. Any thoughts?

Thanks,
Kevin

Diego Medina

unread,
Oct 7, 2012, 2:51:50 PM10/7/12
to lif...@googlegroups.com

Could you try using eager=true  ? I'm on my cell and i can't remember if it goes on the outer snippet or the inner.

Regards

Diego

Diego
Sent from my android cell

--
--
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
 
 
 

AGYNAMIX Torsten Uhlmann

unread,
Oct 7, 2012, 3:15:45 PM10/7/12
to lif...@googlegroups.com
eager_eval="true" needs to be added to the outer snippet...

-- 
AGYNAMIX(R). Passionate Software.
Inh. Torsten Uhlmann | Buchenweg 5 | 09380 Thalheim
Phone:       +49 3721 273445
Fax:             +49 3721 273446
Mobile:       +49 151 12412427
Web:           http://www.agynamix.de

Kevin

unread,
Oct 7, 2012, 10:14:33 PM10/7/12
to lif...@googlegroups.com
Hi Diego, Torsten, I tried adding eager_eval=true on both the outer snippet and the embed tags, and neither worked:

    <div class="lift:ChooseTemplate?eager_eval=true">
      <div id="normal" class="lift:embed?what=normal_template"></div>

      <div id="mobile" class="lift:embed?what=mobile_template"></div>
    </div>

    <div class="lift:ChooseTemplate">
      <div id="normal" class="lift:embed?what=normal_template;eager_eval=true"></div>
      <div id="mobile" class="lift:embed?what=mobile_template;eager_eval=true"></div>
    </div>

    <div class="lift:ChooseTemplate?eager_eval=true">
      <div id="normal" class="lift:embed?what=normal_template;eager_eval=true"></div>
      <div id="mobile" class="lift:embed?what=mobile_template;eager_eval=true"></div>
    </div>

Diego Medina

unread,
Oct 7, 2012, 10:57:03 PM10/7/12
to lif...@googlegroups.com
Thanks Torsten,

@Kevin: This is very strange, could you put together a sample app showing this?
https://www.assembla.com/wiki/show/liftweb/Posting_example_code

I have used eager_eval before to solve this issue, so I hope it is not broken.

Thanks

Diego
--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://www.fmpwizard.com

Kevin

unread,
Oct 8, 2012, 12:10:38 AM10/8/12
to lif...@googlegroups.com
Hey Diego, thanks very much for taking a look! The reproduced problem is in the lift_blank project here:

git clone git://github.com/kevg/lift_25_sbt.git

The diff for the changes I made are here: https://github.com/kevg/lift_25_sbt/commit/c8803daf95c6e007409de672e1dcb5231d97177a

AGYNAMIX Torsten Uhlmann

unread,
Oct 8, 2012, 2:52:31 AM10/8/12
to lif...@googlegroups.com
Hi Kevin,

in the code I nowhere see an eager_eval, did you miss it?

In the Lift source (SnippetSpec) it is embedded like this:

<div class="l:foo?eager_eval=true">a<lift:foo>b</lift:foo></div>

Kind Regards,
Torsten.


-- 
AGYNAMIX(R). Passionate Software.
Inh. Torsten Uhlmann | Buchenweg 5 | 09380 Thalheim
Phone:       +49 3721 273445
Fax:             +49 3721 273446
Mobile:       +49 151 12412427
Web:           http://www.agynamix.de

Kevin

unread,
Oct 8, 2012, 3:12:46 PM10/8/12
to lif...@googlegroups.com
Hi Torsten, I had just tested eager_eval=true and it didn't work but I didn't commit eager_eval=true. The change is committed now with:


    <div class="lift:ChooseTemplate?eager_eval=true">                                                                                                                          
       <div id="normal" class="lift:embed?what=normal_template"></div>                                                                                                          
       <div id="mobile" class="lift:embed?what=mobile_template"></div>                                                                                                          
     </div>

Diego Medina

unread,
Oct 8, 2012, 5:03:26 PM10/8/12
to lif...@googlegroups.com
ok, I pulled the latest from your branch,

I go to http://127.0.0.1:8080/index?mobile=true and the page is just
blank, is this what you see too? can you get even a regular snippet
working?

I guess having detail steps on what we should do to see what you see,
and details on what you see, but expect to see would help.

Thanks

Diego

Kevin

unread,
Oct 9, 2012, 7:01:14 PM10/9/12
to lif...@googlegroups.com
Hi Diego, That's the problem. If you remove eager_eval=true, then you won't see a blank screen, but the "content" div will not be updated with the actual page contents (although the correct template embed is chosen based on mobile=true).

The basic problem is that I would like to select a template based on some boolean logic to test whether a request is coming from a mobile phone or not. I had used David's example of a snippet that chooses the correct embed and I'm unable to make it work with any combination of eager_eval. However, if there's an alternative way to do this, that is just as good.

Thanks.

Diego Medina

unread,
Oct 9, 2012, 7:56:21 PM10/9/12
to lif...@googlegroups.com
Ah, ok, I'll try again tonight then :)

Diego

Diego Medina

unread,
Oct 10, 2012, 12:49:47 AM10/10/12
to lif...@googlegroups.com
ok, so I could not get eager_eval to do what I wanted, so I ended up
with a different solution

https://github.com/fmpwizard/lift_25_sbt/commit/40383f9add27082c59ec656d964dc03d19a41602

Hope that helps.

Diego

AGYNAMIX Torsten Uhlmann

unread,
Oct 10, 2012, 3:09:07 AM10/10/12
to lif...@googlegroups.com
Clever.


-- 
AGYNAMIX(R). Passionate Software.
Inh. Torsten Uhlmann | Buchenweg 5 | 09380 Thalheim
Phone:       +49 3721 273445
Fax:             +49 3721 273446
Mobile:       +49 151 12412427
Web:           http://www.agynamix.de

Diego Medina

unread,
Oct 10, 2012, 7:04:47 AM10/10/12
to lif...@googlegroups.com

Thanks

Diego
Sent from my android cell

Kevin

unread,
Oct 17, 2012, 5:08:30 PM10/17/12
to lif...@googlegroups.com
Sorry, I didn't get an email notification about this reply. Thanks very much for getting it to work!

Peter Petersson

unread,
Oct 17, 2012, 5:38:05 PM10/17/12
to lif...@googlegroups.com

A question still reminds in my head, why did not  eager_eval work ? I am on my cell and have not looked at the code but I think both you and Torsten was right on track when you suggested it.

--from my cell
best regards Peter Peterson

Diego Medina

unread,
Oct 17, 2012, 6:12:20 PM10/17/12
to lif...@googlegroups.com
On Wed, Oct 17, 2012 at 5:38 PM, Peter Petersson
<peterss...@gmail.com> wrote:
> A question still reminds in my head, why did not eager_eval work ? I am on
> my cell and have not looked at the code but I think both you and Torsten was
> right on track when you suggested it.
>

a wild guess is that the surround snippet works differently than a
regular snippet, but I haven;t had the chance to look any further.

Diego

David Pollak

unread,
Oct 17, 2012, 6:28:23 PM10/17/12
to lif...@googlegroups.com
The surround snippet eagerly evaluates the thing being surrounded before putting it inside the template. That way, stuff like messages, etc. get displayed correctly.
Telegram, Simply Beautiful CMS https://telegr.am
Lift, the simply functional web framework http://liftweb.net


Diego Medina

unread,
Oct 18, 2012, 12:12:51 AM10/18/12
to lif...@googlegroups.com
Thanks fir the clarification.

Diego
Reply all
Reply to author
Forward
0 new messages