【发布时间】:2013-01-31 20:42:40
【问题描述】:
我的一个 HAML 模板中有这个:
:markdown
#{render 'home.md'}
在home.md 我有:
There are **#{@photo_count}** photos.
查看网站时,它会逐字输出。如何获取要插值的 @photo_count 变量?
【问题讨论】:
我的一个 HAML 模板中有这个:
:markdown
#{render 'home.md'}
在home.md 我有:
There are **#{@photo_count}** photos.
查看网站时,它会逐字输出。如何获取要插值的 @photo_count 变量?
【问题讨论】:
对于纯 Markdown 文件,我认为您无法做您想做的事情,因为格式本身不支持您的 Ruby 变量。
如果您不介意将 markdown 文件更改为 HAML 部分文件(无需更改其内容),您可以执行类似的操作(我使用了类似于下面的代码,使用了 RDiscount gem ; 您的里程可能会因其他 Markdown 宝石而异...):
app/controllers/pages_controller.rb
def home
@photo_count = 10
end
app/views/pages/home.html.haml
:markdown
#{render 'home_page'}
app/views/pages/_home_page.html.haml
There are **#{@photo_count}** photos.
有关其他想法,另请参阅此 StackOverflow 问答:
【讨论】: