简体   繁体   中英

Rails 4, render a partial/layout with optional block within haml

I have created a haml-partial which I want to use as a default header. When rendering this out I optionally want to give it a block to replace a part of the default content.

I've tried multiple things:

render partial: "partial", capture: do
# Don't really know why I tried this, Syntax error ofcourse.

render partial: "partial" do
# 'nil' is not an ActiveModel-compatible object. It must implement :to_partial_path.

render layout: "partial" do
# Works, but:

render layout: "partial"
# You invoked render but did not give any of :partial, :template, :inline, :file or :text option.
# So, it always needs the block

Any other options I don't know of?

Use render layout: "" when you need a block.

Use render partial: "" when you don't use a block.

They both work with locals and look for a pre-underscored file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM