Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meta Descritpion in HAML with outside variable

I'm trying to get my meta description to work in HAML and everything I try produces errors.

%meta{:name => "description", :content => "Some content"}/
%title 
  = data.page.title

The code above works. Now I try the following:

 %meta{:name => "description", :content => 
   = data.page.desc
   }/
 %title 
   = data.page.title

And I get unbalanced brackets error on the first line. What am I doing wrong?

like image 887
Noah Clark Avatar asked Feb 04 '12 19:02

Noah Clark


People also ask

Can you have HTML in meta description?

The meta description is an HTML tag you can set for a post or page of your website. In it, you can describe what your page is about.

What should I put for meta description in HTML?

The <meta> tag defines metadata about an HTML document. Metadata is data (information) about data. <meta> tags always go inside the <head> element, and are typically used to specify character set, page description, keywords, author of the document, and viewport settings.

Can meta tags be placed anywhere?

meta tags can be added anywhere in the HTML. The web crawlers can read them but the only issue is when you have to share your pages over some application like facebook messenger, whatsapp etc. These applications only read meta tags present inside the head tag.

Should meta description have CTA?

Include a CTA in Your Meta DescriptionsUsing a call-to-action (CTA) in your meta descriptions is a great way to compel people to click on your website. You can use phrases like “Learn More” or “Click Here” or “Shop Now,” when they see it come up in SERPs.


1 Answers

In HAML, the hash that you use to specify the attributes for an element can contain valid Ruby code, so you don't need to use = to evaluate a Ruby expression. Therefore, the code you're looking for is simply:

%meta{:name => "description", :content => data.page.desc}

Note that you don't need to append a / to the end of the %meta element declaration, as HAML will automatically treat it as a self-closing tag, like img or br.

like image 99
Leo Cassarani Avatar answered Sep 23 '22 07:09

Leo Cassarani