yuya-matsushima / middleman-slim

A Middleman template using Slim.
MIT License
64 stars 7 forks source link

yield_content doesn't correctly work #3

Closed Nowaker closed 9 years ago

Nowaker commented 10 years ago

Consider this code:

- content_for :a do
  | Content A

| Content Main

- content_for :b do
  | Content B

And the layout:

doctype html
html
  body
    .test
    | Content for A:
    = yield_content :a
    br

    | Content for main:
    = yield
    br

    | Content for B:
    = yield_content :b
    br

The output is:

Content AContent B
Content for A:Content A
Content for main:Content Main
Content for B:Content AContent B

But should be:

Content for A:Content A
Content for main:Content Main
Content for B:Content AContent B

What's interesting - it works OK when templates are in slim, and the layout is in ERB. The problem is somewhere in the layout rendering.

Somebody has already been affected by this. https://stackoverflow.com/questions/13954529/how-to-use-content-for-yield-content-in-middleman-using-slim

A minimal test case: https://github.com/Nowaker/middleman-slim-bugreport

yuya-matsushima commented 10 years ago

You must use = instead of -.

Check "Slim and Haml Content Blocks" section in Upgrading Padrino from 0.11.X to 0.12.0 Guide

Middleman use Padrino-helper and Middleman(> v3.3.0-3.3.2)'s behavier is changed when using slim and haml. (changelog)

Nowaker commented 10 years ago

Well, it works better but still not quite right. Since = prints the returns value, I have a Proc in the output.

[#<Proc:0x007fd8c8daf7e8@/home/nowaker/projekty/ruby/virtkick-prototype/source/appliances.html.slim:38>]

Nowaker commented 10 years ago

After changing - to @ in the minimal test case I provided the output is:

Content for A:Content A
Content for main:[#]Content Main[#]
Content for B:Content B

We see [#] because <Proc ...> part is considered as tag and thus not rendered by the browser.

yuya-matsushima commented 10 years ago

Sorry, I don't know about Proc problem. This problem is not a bug by middleman-slim.

Please talk in Middleman Forum.

milesegan commented 10 years ago

I found a workaround for this. You can write your content_for section this way:

- content_for :title, "My Title Is Here."
Nowaker commented 10 years ago

@milesegan Yes, but it's quite a poor workaround, applicable to short texts only.

milesegan commented 10 years ago

@Nowaker Agreed. It would be nice to have a proper fix for this. But it was enough for me to move on and finish my project at least.

pedromaltez commented 9 years ago

Looks like this should be closed. The problem has been fixed in middleman.

Nowaker commented 9 years ago

Yes, all fixed. Thanks @pedromaltez.