Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
Locked
0

Pass variable to template with liquid?

Participant ,
May 28, 2015 May 28, 2015

Can we with Liquid pass variables to the template file?

For this case I want to to pass blog post title, description etc. into the <head> of my template to use the Facebook OG-graph meta tags.

Thanks!

TOPICS
Developer
3.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 28, 2015 May 28, 2015

To pass liquid variables from pages or templates into module templates like web apps or product layouts you need to output the list as a collection on the page or use a liquid include in conjunction with a collection. Liquid variables do not pass through to module templates/layouts. Otherwise you'll have to declare your variable within the module template file.

In your example though why wouldn't you just use the built in blog modules metadata fields and insert as tags or liquid tags in the detail layout? If you wanted to specify meta data that will be the same for each blog post then you should probably just create a new template and hard code that information in the <head>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 28, 2015 May 28, 2015

Scott, I want to pass it into the page template. Facebook/Twitter/LinkedIn all have special meta tags. The client dosn't want to write manual code, they just want to fill in the standard meta and get the data copied into the other meta-tags by the template file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 28, 2015 May 28, 2015

Sorry, if i'm still not understanding but if you're using the built-in blog module in bc this is what your blog post layout would look like. BC will kick the meta tag information into the <head> of your page template then. If you need to fill in more social media meta information, like image, you might want to go with a web app blog option.

<html>

<head>

<title>{{metaTitle}}</title>

<meta name="description" content="{{metaDescription}}">

<meta property="og:site_name" content="Site Name">

<meta property="og:type" content="article">

<meta property="og:title" content="{{title}}">

<meta property="og:url" content="{{url_withhost}}">

<meta property="og:description" content="{{metaDescription}}">

<meta property="article:publisher" content="https://www.facebook.com/companypage">

<meta name="twitter:site" content="@companyhandle">

<meta name="twitter:title" content="{{title}}">

<meta name="twitter:description" content="{{metaDescription}}">

</head>

<body>

<h1>{{title}}</h1>

{{body}}

</body>

</html>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 28, 2015 May 28, 2015

Thanks for your suggestion, unfortunately it doesn't work.

It outputs:

<meta property="og:url" content="{{url_withhost}}">

<meta property="og:description" content="{{metaDescription}}">

The liquid tags is not available. That is my question - how do I pass liquid variables into the template head?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 02, 2016 Jan 02, 2016

This is an issue I'm having as well with social meta tags in page templates.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 02, 2016 Jan 02, 2016

Read what I put.

You place head code at the bottom of your large layout, blog, web app, product.... Any of those.

Then put your meta in there with the tags / liquid ouput items available in that layout. BC will put them in the head on page render.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 04, 2016 Jan 04, 2016
LATEST

I can confirm what Liam is saying here.

For all my blogs, product detail pages and some web app detail pages (where necessary), by simply adding your <meta property="og:xxx"> into the <body> of the detail page, BC's rendering will automatically place all <meta> tags into the <head> section of your website.

It's a brilliant feature in BC, one which has been around for several years now.

This should work very well for you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 28, 2015 May 28, 2015

Scott,

What you said is not actually 100%

{module_webapp mycustomvar="WHATEVERLIQUIDTHINGIAMPASSING" ....

Will allow this.params.mycustomvar to work in the module.


Antun,


<head>

STUFF HERE

</head>


- If a blog put that in your detail layout, use the blog tags available, you will not be able to do an image of course

- Do not need or: url unless your doing something custom with lists - they will pick it up, same with meta description

- For a web app if it has image field you can do that and anything else and again put it in your detail layout


And so on, these will be pushed into the actual head of the rendered page by BC.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines