1

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?

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

you can try the following:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.