Using instance variables to populate frontmatter when generating articles?

I want each new article I generate to automatically populate the frontmatter with the title, date, etc.

In the documentation for blogging under Generating Articles it states you can use instance variables such as @title to do so, but when I reference that variable in the frontmatter of my custom article template (which is in haml), it doesn’t seem to do anything:

---
title: @title 
date: @date
tags: ---

I know it’s likely a rookie mistake. Thanks for your patience!

I have not tested it, but try

title: #{@title}

Tried it but it unfortunately does not seem to work.

I’ve been trying to figure this out so I can dynamically create a blog article title based off data/*.yml files.

You can try to use my solution for a similar problem: I18n string translation and frontmatter

I’m using it in my real work, it’s a workaround, but working.

The following worked for me:

# config.rb
activate :blog do |blog|
  blog.new_article_template = "source/templates/blog.markdown"
end
# source/templates/blog.markdown
---
title: <%= @title %>
date: <%= @date %>
tags:
  - "blog"
---
# blog/2015-07-07-blog-post.html.markdown
---
title: Blog post
date: 2015-07-07 08:37:01 UTC
tags:
  - "blog"
---
1 Like

Great hack, but it’s limited to blog mode only. I use my I18n code in non-blog projects, so there is no separate article-layout.