Sinatra Textile 模板

2023-12-19 16:15 更新

需要引入 ?RedCloth? gem/library 以填充 Textile 模板:

# 在你的應(yīng)用中引入redcloth
require "redcloth"

get '/' do
  textile :index
end

這里調(diào)用的是 ?./views/index.textile?。

在 textile 中是不可以調(diào)用方法的,也不可以傳遞 locals 給它。 你因此一般會(huì)結(jié)合其他的填充引擎來使用它:

erb :overview, :locals => { :text => textile(:introduction) }

請(qǐng)注意你也可以從其他模板中調(diào)用?textile?方法:

%h1 Hello From Haml!
%p= textile(:greetings)

既然你不能在 Textile 中調(diào)用 Ruby,你不能使用 Textile 編寫的布局。 不過,使用其他填充引擎作為模版的布局是可能的, 通過傳遞:?layout_engine?選項(xiàng):

get '/' do
  textile :index, :layout_engine => :erb
end

這將會(huì)填充? ./views/index.textile? 并使用? ./views/layout.erb? 作為布局。

請(qǐng)記住你可以全局設(shè)定這個(gè)選項(xiàng):

set :textile, :layout_engine => :haml, :layout => :post

get '/' do
  textile :index
end

這將會(huì)調(diào)用 .?/views/index.textile? (和任何其他的 Textile 模版) 并使用 ?./views/post.haml? 作為布局。


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)