Alternate/mobile version of web app

89 views
Skip to first unread message

Tobias Pfeiffer

unread,
Aug 7, 2012, 9:21:59 AM8/7/12
to lif...@googlegroups.com
Hi,

I got a web application with Lift up and running at www.myhost.com, now I
want to add a mobile version of that app at m.myhost.com, i.e. I need to
select different templates when the user visits m.myhost.com.
www.myhost.com/article/12345 should use article/star.html, but
m.myhost.com/article/12345 should use m/article/star.html or so.
In particular, it should still be possible to have a template selected
depending on the locale (m/article/star_de.html).
Any experiences or hints on how to do that?

Thanks
Tobias



signature.asc

David Pollak

unread,
Aug 7, 2012, 12:33:03 PM8/7/12
to lif...@googlegroups.com
Personally, I put my template choosing logic in /templates-hidden/default.html

Something like:

<lift:ChooseTemplate>
  <lift:embed id="mobile" what="mobile_template"/>
  <lift:embed id="desktop" what="desktop_template"/>
</lift:ChooseTemplate>

Then in your ChooseTemplate snippet:

object ChooseTemplate {
  def render = if (isMobile) "#mobile ^^" #> true else "#desktop ^^" #> true
}

Hope this helps.

--
Telegram, Simply Beautiful CMS https://telegr.am
Lift, the simply functional web framework http://liftweb.net


Stefan Bradl

unread,
Aug 7, 2012, 3:30:26 PM8/7/12
to lif...@googlegroups.com
I am doing it this way:

Snippet:
class TemplateSelector {

  def render(children: NodeSeq) = {
    S.withAttrs(metadata)({
      Surround.render(children)
    })
  }

  def template = UserAgentDetector.isMobile match {
    case true => "mobile"
    case false => "default"
  }

  def content = "content"

  private def metadata: MetaData = Attribute(None, "at", Text(content),
    Attribute(None, "with", Text(template), Null))
}

Template:

<div id="main" data-lift="TemplateSelector">
...
</div>

2012/8/7 David Pollak <feeder.of...@gmail.com>

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

Diego Medina

unread,
Aug 7, 2012, 4:21:43 PM8/7/12
to lif...@googlegroups.com
On Tue, Aug 7, 2012 at 12:33 PM, David Pollak
<feeder.of...@gmail.com> wrote:
> Personally, I put my template choosing logic in
> /templates-hidden/default.html
>
> Something like:
>
> <lift:ChooseTemplate>
> <lift:embed id="mobile" what="mobile_template"/>
> <lift:embed id="desktop" what="desktop_template"/>
> </lift:ChooseTemplate>
>
> Then in your ChooseTemplate snippet:
>
> object ChooseTemplate {
> def render = if (isMobile) "#mobile ^^" #> true else "#desktop ^^" #> true
> }
>

I don;t want to lose this one, so I added it here
http://www.assembla.com/spaces/liftweb/wiki/Cool_Tips#select_mobile_vs_desktop_templates

Thanks

Diego

> Hope this helps.
>
>
> On Tue, Aug 7, 2012 at 6:21 AM, Tobias Pfeiffer <tob...@tesobe.com> wrote:
>>
>> Hi,
>>
>> I got a web application with Lift up and running at www.myhost.com, now I
>> want to add a mobile version of that app at m.myhost.com, i.e. I need to
>> select different templates when the user visits m.myhost.com.
>> www.myhost.com/article/12345 should use article/star.html, but
>> m.myhost.com/article/12345 should use m/article/star.html or so.
>> In particular, it should still be possible to have a template selected
>> depending on the locale (m/article/star_de.html).
>> Any experiences or hints on how to do that?
>>
>> Thanks
>> Tobias
>>
>>
>>
>
>
>
> --
> Telegram, Simply Beautiful CMS https://telegr.am
> Lift, the simply functional web framework http://liftweb.net
> Follow me: http://twitter.com/dpp
> Blog: http://goodstuff.im
>
>
> --
> --
> Lift, the simply functional web framework: http://liftweb.net
--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://www.fmpwizard.com

Lukasz Kuczera

unread,
Aug 9, 2012, 3:42:52 AM8/9/12
to lif...@googlegroups.com
We wen't a little bit different direction (deployment issues etc.) And all mobile we have under /mobile/ This way we do only single redirect to /mobile/ and rest takes care of itself. Templates are separated so we don't have to have logic that choose them (we had issues because of proxy servers). Another benefit is we don't have to setup separate SSL and domain. I know whole world is using m. subdomain but I as a user don't care about domain name as long as this thing work.
Reply all
Reply to author
Forward
0 new messages