Ticket #23 (assigned defect)

Opened 2 years ago

Last modified 20 months ago

Mixing rhtml, mab, and content_for

Reported by: joeruby Owned by: why
Priority: major Milestone: 1.0
Component: gem Version: 0.5
Keywords: sub-templates rthml Cc:

Description

Creating sub-templates using content_for doesn't seem to work when used with rhtml templates. e.g.

application.rhtml
  h1 'application'
  <%= @content_for_layout %>

members.mab
  @content = @content_for_layout
  @content_for_layout = nil

  content_for('layout') do
    h2 'members'
    self << @content
  end

  render 'layouts/application', :content_for_layout=@content_for_layout

members/index.mab
  h3 'index'

With the above, application and index get rendered, but for some reason not members. If I change application.rhtml to a Markaby template, it works.

Change History

Changed 2 years ago by zimbatm

Shouldn't yield be used instead of @content_for_layout in the layout ?

Changed 2 years ago by joeruby

How? I haven't been able to figure out how to use yield in Markaby:

yield

(eval):236:in `render': no block given

self << yield

(eval):236:in `render': no block given

Changed 2 years ago by why

  • status changed from new to assigned

Okay, so, a few things:

  • You can't use h1 in an rhtml template.
  • There's a syntax error in the members.mab file. Use an arrow:
        :content_for_layout => @content_for_layout
    
  • I've tested with the latest Rails and Markaby and it works for me. Could you try again and let me know all the version numbers (Ruby, Rails, Markaby.)

Changed 2 years ago by joeruby

Right, right -- the first two were just errors in my report! I'm using:

Rails 1.1.6 Ruby 1.8.4 Markaby 0.4

Changed 2 years ago by why

  • milestone set to 1.0

Changed 20 months ago by srackham

Same behavior on Rails 1.2.1, Ruby 1.8.5, Markaby 0.5. 'yield :layout' generates a 'no block given' error when used in in Markaby layouts (also discussed here http://www.ruby-forum.com/topic/76509). The deprecated @content_for_layout returned nil (also discussed here http://www.ruby-forum.com/topic/91598). I don't know of a workaround other than not using Markaby for layouts.

Note: See TracTickets for help on using tickets.