grails header title not working with layout - sitemesh and layout - grails

I have a base header layout (base-header-footer.gsp)
<!DOCTYPE html>
<html>
<head>
<title><g:layoutTitle default="${g.message(code: 'title.index.page')}"/></title>
</head>
... some common resources loading....
<body id="launch">
<g:layoutBody/>
...........................
<r:layoutResources />
</body>
</html>
And then 2 more header, one for logged-in user, and another for guest users, and both of these header layout are extending the base layout.
Guest users (anonymouys-header-footer.gsp) -
<g:applyLayout name="base-header-footer">
<!DOCTYPE html>
<html>
<head>
<g:layoutHead/>
</head>
<body>
... render guest user header
<g:layoutBody/>
</body>
</html>
Logged-in users (loggedin-header-footer.gsp) -
<g:applyLayout name="base-header-footer">
<!DOCTYPE html>
<html>
<head>
... some css
<g:layoutHead/>
</head>
<body>
... Render header for logged-in user
</body>
... load some JS file...
</html>
Now in specific pages I apply guest OR logged-in layout based on user's login state, hence I want to show the page specific title user is on, but it doesn't work.
This is how I am using those layout
OrderStatus.gsp -
<!DOCTYPE html>
<html>
<head>
<title>Order status | Some title</title>
<meta name="layout" content="logged-in-header-footer" />
<script type="text/javascript" src="${resource(dir:'js',file:'some.js')}"></script>
</head>
<body>
</body>
</html>
But I still see the title which is defined base-header-footer.gsp, not the one in OrderStatus.gsp
I have also tried using g:layoutTitle in OrderStatus.gsp but doesn't help.
Any help is highly appreciated.

Use
<meta name="layout" content="base-header-footer">
in your pages to load the layout, then add your title there,
<title>${whatever.something()}</title>
in your layout add this:
<title><g:layoutTitle/></title>
enjoy.

Try to use
<title><g:layoutTitle/></title>
in your layouts (base-header-footer and loggedin-header-footer.gsp). More info in the official documentation.

Related

style tag is ignored by uiwebview

I'm trying to give my html an css inline style. But this style gets ignored.
This is the HTML string that I'm using for webView.loadHTMLString(htmlBelow, baseURL: Bundle.main.bundleURL)
let fontsize = 16 //This is an dynamic variable
<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
<meta http-equiv=\"X-UA-Compatible\"content=\"ie=edge\">
<title>Document</title>
<style>
​html {
font-size:\(fontsize)px; */THIS DOESN'T WORK/*
}
</style>
<link rel=\"stylesheet\" href=\"\style.css\">
<script src=\"jquery-3.4.1.min.js\"></script>
<script src=\"script.js\"></script>
</head>
<body>
<div class=\ "sqr-tree-level\"> \(restOfHtml) </div>
</body>
</html>
I'm trying to set the fontsize dynamically.
When I change the font-size in my css file it works, but I want to set it dynamically. That's why I wanna do it like this.
This is how my document.head.innerHTML looks like
For future reference the fix here was to put the styling in to the <body> tag instead of in the head <style> tag.
<body style=\"font-size:\(fontsize)px;\">

Rails Internal Style For Mailer Template Not Working

Internal style written in rails mailer template is not working.
<html>
<head>
...
...
</head>
<body>
<style type="text/css">
...
...
</style>
</body>
</html>
How to solve this problem?
Make sure that you are putting internal style inside head tag
eg:
<head>
<style type="text/css">
...
...
</style>
</head>
Note: Only internal style (must be in head tag) supports.

GSP variables set in layout not visible in pages

I have some GSP variables set in the "main" layout file of my Grails application (included below). The values of these variables don't appear to be accessible in the GSP pages that are rendered by the sitemesh. Also, they are not visible in any templates that are rendered by the tag. I have tried setting the scope="request" (see code) below, but that doesn't appear to make any difference. I'm clearly not understanding the scoping rules for GSP variables.
Can anyone clarify how GSP variables are scoped and make a recommendation on how I can communicate them from the layout all the way down to templates (if I can at all).
<!DOCTYPE html>
<%-- <html lang="${org.springframework.web.servlet.support.RequestContextUtils.getLocale(request).toString().replace('_', '-')}"> --%>
<html lang="${session.'org.springframework.web.servlet.i18n.SessionLocaleResolver.LOCALE'}">
<head>
<title><g:layoutTitle default="${meta(name:'app.name')}" /></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<asset:javascript src="bootstrap.js" />
<theme:load />
<asset:javascript src="application.js" />
<asset:stylesheet src="application.css" />
<asset:link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<g:layoutHead />
<%-- Defineform body layout column dimensions. These values are used by Bootstrap based forms to
layout using configured column widths and offsets. --%>
<g:set var="labelWidth" value="${grailsApplication.config.ark.layout.labelWidth ?: 'col-sm-3'}" scope="request" />
<g:set var="controlWidth" value="${grailsApplication.config.ark.layout.controlWidth ?: 'col-sm-4'}" scope="request" />
<g:set var="controlOffset" value="${grailsApplication.config.ark.layout.controlWidth ?: 'col-sm-offset-3'}" scope="request" />
<%-- For Javascript see end of body --%>
</head>
<body>
<g:render plugin="arkUi" template="/layouts/menu/navbar"/>
<g:render plugin="arkUi" template="/layouts/content"/>
<g:render plugin="arkUi" template="/layouts/footer"/>
<!-- Include deferred Javascript files and other resources -->
<asset:deferredScripts/>
</body>
</html>
The issue here is that Grails first parses the target GSP page to (among other things) determine which layout to use, then parses the layout GSP and combines them. So the layout can see variables you set in the page but not vice-versa.

How to downcase an entire HTML document parsed with Nokogiri

I need to downcase all text in an HTML document that has been parsed with Nokogiri. Here my code:
agent = Mechanize.new
page = agent.get('http://www.example.com').parser.search('//*[translate(text(),"ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz") = *]').to_html
There is not error as such in the code; it executes without an error. If I go in and check a random tag in the document, however, the case is still the same as before. Is there another/better way to downcase all text in a document?
You could use traverse to downcase all text nodes:
require 'open-uri'
require 'nokogiri'
doc = Nokogiri::HTML(open("http://www.example.com/"))
doc.traverse do |node|
node.content = node.content.downcase if node.text?
end
puts doc.to_html
Output:
<!DOCTYPE html>
<html>
<head>
<title>example domain</title>
<meta charset="utf-8">
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
body { ... }
</style>
</head>
<body>
<div>
<h1>example domain</h1>
<p>this domain is established to be used for illustrative examples in documents. you may use this
domain in examples without prior coordination or asking for permission.</p>
<p>more information...</p>
</div>
</body>
</html>

Facebook OG: Register achivement doesn't work

I'm trying to register facebook open graph achivement, but It doens't work.
Get app access token like this:
https://graph.facebook.com/oauth/access_token?client_id=APP_ID&client_secret=SECRET&grant_type=client_credentials
HTML page look like this:
<html>
<head>
<meta property="og:type" content="game.achievement"/>
<meta property="og:title" content="TITLE"/>
<meta property="og:description" content="DESCRIPTION"/>
<meta property="og:url" content="URL/testAchivement.html"/>
<meta property="og:image" content="URL_TO_IMAGE"/>
<meta property="game:points" content="10"/>
<meta property="fb:app_id" content="APP_ID"/>
<title>ACHIEVEMENT!</title>
</head>
<body>
</body>
</html>
I use this:
https://graph.facebook.com/APP_ID/achievements?achievement=MYSERVER/testAchivement.html&display_order=2&access_token=APP_ACCESS_TOKEN
and get this response:
{
"data": [
]
}
No errors when using facebook debug tool.
Please help , thanks!

Resources