Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to nest a div within another div from a for loop using slim

I have the following code

div class = "content"
- for x in list
  -if x == "test"
    div id = "two"

I would expect div id = "two to be nested within div class="content however it appears as its own separate div. How would I go about nesting the div within the content div based on the conditional?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to indent lines 2-4, otherwise they’re treated as siblings. To quote the docs

Indentation matters, but the indentation depth can be chosen as you like. If you want to first indent 2 spaces, then 5 spaces, it’s your choice. To nest markup you only need to indent by one space, the rest is gravy.

div class = "content"
  - for x in list
    -if x == "test"
      div id = "two"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading