Lift Html Tag Value

31 vues
Accéder directement au premier message non lu

Nicola Contu

non lue,
11 mai 2016, 10:09:0011/05/2016
à Lift
Hey guys,
Is there any trick to set a value in the html tag via css selector?

I have a multilingual website and I need to set the language in the html tag with the language selected by the user.

I was desperate so I tried also this below but this is not working obviously :

HTML:

<lift data-lift="getLocale">
<html lang="" id="cur-lang">
</lift>
<head>
  .......
</head>
<body>
 .....
</body>
</html>



SNIPPET :
    "#cur-lang [lang]" #> locale


Where locale contains the correct string to be inserted.

So is there any other way I can try? Like wrapping all the html in a snippet?

Can you help?

Thanks a lot,
Nicola



Brett Grace

non lue,
11 mai 2016, 14:21:2111/05/2016
à Lift
Given the following in your template (NB: if you are using lift-surround, it has to be in the surrounding template!)

<html class="no-js" lang="en" data-lift="SetLocale.langAttr">

and the following snippet:

object SetLocale {
 
def langAttr = {
   
"html [lang]" #> "klingon"
  }
}

Then the following HTML is served:

<html lang="klingon" class="no-js">

This is using Lift 3.0RC1.

Also note that if you something like <!--[if IE 9]>, it won't work, Lift strips comments so it won't see the snippet.


Nicola Contu

non lue,
12 mai 2016, 04:28:1212/05/2016
à Lift
Great thanks that worked.

Nicola

Brett Grace

non lue,
12 mai 2016, 11:56:2012/05/2016
à Lift
I'm glad that worked for you. In case you haven't looked into it, Lift does have a localization/internationalization mechanism, including (I believe) template selection based on the user agent's locale settings.

See https://www.assembla.com/wiki/show/liftweb/Localization, https://www.assembla.com/wiki/show/liftweb/internationalization

Antonio Salazar Cardozo

non lue,
17 mai 2016, 22:13:4717/05/2016
à Lift
On Wednesday, May 11, 2016 at 2:21:21 PM UTC-4, Brett Grace wrote:
Also note that if you something like <!--[if IE 9]>, it won't work, Lift strips comments so it won't see the snippet.

Though there are ways to deal with this fairly easily by using a snippet to
generate the conditional comments; e.g.:

object InternetExplorer {
  def snippetHandlers: SnippetPF = {
    case "if-ie" :: Nil => conditionalComment _
  }

  def conditionalComment(xhtml: NodeSeq) = {
    val ieVersion = S.attr("version") openOr "IE"
    Unparsed("<!--[if " + ieVersion + "]>") ++ xhtml ++ Unparsed("<![endif]-->")
  }
}

 <link data-lift="if-ie" rel="stylesheet" href="/static/css/ie.css">
 <script data-lift="if-ie?version=lt IE 9" src="/static/js/html5shiv.js"></script>

Thanks,
Antonio
Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message