Ruby on rails 使用Slim在Nanoc中将变量从内容传递到布局
我主要想知道使用Nanoc和Slim将ruby变量从内容页传递到布局的最简单方法。我在想这样的事情: content/content.slim:Ruby on rails 使用Slim在Nanoc中将变量从内容传递到布局,ruby-on-rails,ruby,model-view-controller,slim-lang,nanoc,Ruby On Rails,Ruby,Model View Controller,Slim Lang,Nanoc,我主要想知道使用Nanoc和Slim将ruby变量从内容页传递到布局的最简单方法。我在想这样的事情: content/content.slim: --- title: Writeups layout: /layout.slim --- - age = get_age --- title: Mister Tree --- p Hello there! - content_for :age | hundreds of years layout/layout.slim: doctype h
---
title: Writeups
layout: /layout.slim
---
- age = get_age
---
title: Mister Tree
---
p Hello there!
- content_for :age
| hundreds of years
layout/layout.slim:
doctype html
html
head
== yield
p I am #{@item[:title]} and am #{@item[:age]} years old
doctype html
html
body
== yield
p I am #{@item[:title]} and am #{content_for(@item, :age)} years old
我知道如何通过frontmatter访问值,但frontmatter的值是固定的,我想要的是一个ruby函数来为我查找该值。Nanoc提供了一个功能,它可以在一个地方“捕获”内容并在其他地方使用
content/content.slim:
---
title: Writeups
layout: /layout.slim
---
- age = get_age
---
title: Mister Tree
---
p Hello there!
- content_for :age
| hundreds of years
layout/layout.slim:
doctype html
html
head
== yield
p I am #{@item[:title]} and am #{@item[:age]} years old
doctype html
html
body
== yield
p I am #{@item[:title]} and am #{content_for(@item, :age)} years old
lib/default.rb(或您选择的lib/中的任何文件):
这将生成以下输出:
<!DOCTYPE html>
<html>
<body>
<p>Hello there!</p>
<p>I am Mister Tree and am hundreds of years years old</p>
</body>
</html>
你好
我是树先生,已经几百岁了
nanoc是否有可用的方法的content\u?我必须使用include
而不是
的content\u。它与您正在使用的nanoc版本相关。