How to set meta data in the play framework? - metadata

I am using the play framework 1.2.6 and can't seem to find a handy way to set the meta data description in the html pages. To set the title there is this:
#{set title:'This is the title' /}
which generates
<title>This is the title</title>
Is there anything similar which would generate this:
<meta name="description" content="This is the description">

Actually, it was much easier than I thought. I just modified this part of code in header.html:
<meta name="description" content="#{get 'description' /}">
And then in a page that extends header.html:
#{set description:'This is the description' /}

Related

Generate dynamic meta tags for Facebook in JSF

How can I generate dynamic meta tags for facebook on server side? Depending upon the data fetched from database, I need to dynamically set the value of og:title, og:description etc.
Can I use HttpServletResponse.addHeaders() to do that? If yes then how to do that?
In JSF, you can just use EL in template text.
<meta property="og:title" content="#{bean.og.title}" />
<meta property="og:description" content="#{bean.og.description}" />
<meta property="og:url" content="#{bean.og.url}" />
...
Bean and model can be prepared and used the usual way here.
See also:
Using JSF EL in a plain HTML attribute

Meta description with special characters in Umbraco

I have a problem when using special characters in meta and alt text in Umbraco.
I am testing with Meta description and Alt text like this: Test test æøå
And it generates this output:
<meta name="description" content="Test test æøå">
<img src="#" alt="Test test æøå" />
If I insert the same text in title tags and normal content, then the output is just perfect.
The code that is generating the meta and title tags looks like this:
<!DOCTYPE html>
<html lang="da">
<head>
<meta charset="utf-8">
<meta name="description" content="#Umbraco.Field("pageDescription")">
<title>#Umbraco.Field("pageTitle")</title>
</head>
The files are saved as utf-8 using Notepad++.
If I insert æøå directly in the HTML, then it shows æøå without any problems.
I have also tried this:
<p>#Umbraco.Field("pageDescription")</p>
And then it shows "æøå" correctly.
Does anybody know what I am doing wrong?
Thanks in advance!
// René
Looks like this is a "feature" of Razor that it will always HTML encode attributes. See: Razor - #Html.Raw() still encoding & in meta tag attributes
So to work around this, you can do the following:
<meta name="description" #Html.Raw("content=\""+ #Umbraco.Field("pageDescription") + "\"") />
<title>#{ var title = new HtmlString(Umbraco.Field("pageTitle").ToString());}#title</title>
It's not pretty, but it works.

Open Graph meta tags not working

I'm trying to implement OG meta tags into my web site, but when I visit facebook debuger tool it reports that og:type is missing although it's not missing.
This is the link for one of my posts: http://objavi.net/posts/9
Don't know if it matters, but I use Laravel 4.
This is the code I use:
<meta property="og:image" content="{{ asset('uploads/' . $post->img) }}">
<meta property="og:title" content="{{ $post->title }}">
<meta property="og:type" content="article">
<meta property="og:url" content="{{ Request::url() }}">
this code is yielded into main layout.
"Whoops, looks like something went wrong."
The page with the tags must be available in public, or Facebook will not be able to parse them.
Edit: It is working now, but the debugger still does not parse the tags. Try putting the meta tags before any CSS or JavaScript code.

dynamically handling metadata

I get data from the server to dynamically create a video gallery on the client. Those data contain metadata-related information such as contributor etc.
I have a standard snippet for dublin core data in my webpage like
<meta name="DC.Source" id="videdsource" />
<meta name="DC.Description" id="metadesv" />
<meta name="DC.Creator" id="videdcreator" />
<meta name="DC.Contributor" id="videdcontr" />
//and so on, for all the dublin core elements...
Each time the users picks another video,I want to dynamically change the metadata values using a code like
document.getElementById("videdcreator").content=arrayvid[i];
This is not working. Because If I load the web page and look at the source code, the dublin core elements that are standard have a value , like
<meta name="DC.Rights" content="Copyright 2014" />
but, the elements that I want to change dynamically, have no values, like
<meta name="DC.Contributor" id="videdcontr" />
How do I fix this?
What is the best practice to dynamically handle multimedia metadata on a webpage?
Thanks
I'm fairly new to JS and to stackoverflow as well. Don't know if this is going to help you, but have you tried the following?
Ex. 1
Have id's to your meta tags -- checked
<meta name="DC.Source" id="videdsource" />
<meta name="DC.Description" id="metadesv" />
<meta name="DC.Creator" id="videdcreator" />
The trigger
object.onclick=changeTags();
JS function
function changeTags(){
$("#videdsource").attr("content","yourlink");
$("#metadesv").attr("content","Coolest video");
$("#videdcreator").attr("content","Chuck Norris");
}
Does this help you in any way?
This is was my mistake, because first of all, metadata dont support id.
But they have a name. So, in pure JS, I can do getElementsByName and then setAttribute
So the code is
//html part
<meta name="DC.Creator"/>
<button id="change" type="button">change it</button>
//javascript part
document.getElementById('change').onclick=myfunc;
var ha="ha";
function myfunc()
{
document.getElementsByName("DC.Creator")[0].setAttribute("content",ha);
}
You can see your changes by doing "inspect element" on your browser
Credits go to the user named "geomagas" on this Greek forum
Use php and do something like
<meta name="DC.Creator" id="videdcreator" content="<?echo $arrayvid["vidcreator"][i];?>"/>

Facebook open graph meta tags & valid html [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Html validation error for property attribute
According to facebook to use their like button and the open graph meta tags you need to place something like this into your html page.
<meta property="og:title" content="The Rock"/>
<meta property="og:type" content="movie"/>
<meta property="og:url" content="http://www.imdb.com/title/tt0117500/"/>
<meta property="og:image" content="http://ia.media-imdb.com/rock.jpg"/>
<meta property="og:site_name" content="IMDb"/>
What the hell are they playing at? This is invalid html, the attribute 'property' is not and never has been an attribute of the meta tag so why on earth have facebook used this instead of <meta name="og:title" content="The Rock" />?
I am reluctant to try on my site live with valid 'name' instead of 'property' because if I do try and it doesn't work on my site then anyone who clicks like while i am testing it out will have their like fail. So ... Does anyone know if I use the use 'name' instead of 'property' will this still work?
Don't forget that they also want you to declare some schemas to the html tag - specifically the open graph one via xmlns:og="http://opengraphprotocol.org/schema/. OG is based on RDFa which adds the additional attributes to the meta tags.
Once you're done with that, be sure to add your fb:like - <fb:like href="http://developers.facebook.com/" width="450" height="80"/> - the example is pretty straightforward. Don't forget to add xmlns:fb="http://www.facebook.com/2008/fbml" otherwise you will be sad
Found this answer on SO regarding validation of the meta tag. Doing what that answer describes should give let you pass it through any w3c validator.