Search code examples
htmlcssrubysassmiddleman

Dynamic content depending on css class


I use middleman for developing a website and want to separate markup from content by using the .yml-file. So here is the question:

Is there a way to change the ruby data path depending on a certain css class?

For example I want to put out certain content only if there a css class in the parent tag:

Something like that

If I use just class "page" the ouput must came from sliderA-Section, from the slider.yml

<div class="page">
    <div class="slider">
        <span class="content">
            <%= data.slider.sliderA.content %>
        </span>
    </div>
</div>

But if I add class "B" to the "page" container, the output must came from the same yml-file but from the SliderB-section in it.

I wish to make this (DYN) part in the data path dynamic by using a variable or so.. which depends on a css-class

<%= data.slider.DYN.content %>

Is something like that possible?


Solution

  • You should be able to access your data dynamically as follows:

    <% DYN = sliderA %>
    <%= data.slider[DYN].content %>
    

    PS: Are you aware of the page_classes helper (http://middlemanapp.com/helpers/#toc_8)? Maybe it could help you, too.