Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法在模板中重复相同的文本块 X 次?例如,我需要生成带有主机名和文本块的模板。
Host1 A lot of text . . HostX A lot of text
each在模板中使用循环:
each
<%- @hosts.each_with_index do |host, n| -%> Host<%= n %> A lot of text involving <%= host %> etc etc <%- end -%>
你可以在 Erb 模板中使用任何普通的 Ruby 流控制东西。