문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

you can try the following:

</%= eval "data.slider.#{dyn}.content" %>

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top