Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterating over double nested structures #121

Open
zuriar opened this issue Apr 19, 2016 · 3 comments
Open

Iterating over double nested structures #121

zuriar opened this issue Apr 19, 2016 · 3 comments

Comments

@zuriar
Copy link
Contributor

zuriar commented Apr 19, 2016

Hi

I have the following structure, passed to Selmer as variable 'res':

[ { :a "A1"
    :b "B1"
     :c [{ :aa "AA1"
            :bb "BB1"
            :cc "CC1"}
          { :aa "AA2"
            :bb "BB2"
            :cc "CC2"}
          { :aa "AA3"
            :bb "BB3"
             :cc "CC3"}]}
    {:a "A2"
     :b "B2"
      :c [{ :aa "AA11"
             :bb "BB11"
             :cc "CC11"}
           { :aa "AA21"
             :bb "BB21"
             :cc "CC21"}
          { :aa "AA31"
            :bb "BB31"
             :cc "CC31"}]}]

I want to iterate over the items in the first vector and print them out, and when getting to the ':c' fields I want to then start an inner iteration to print out the contents.

At the moment it is possible to get to every element in the structure with dotted notation. However, when I introduce an iterator using {% for n in res %} I then can not repeat this for the inner vector. Is this a lacking feature or am I not seeing the bigger picture? Thanks

@yogthos
Copy link
Owner

yogthos commented Apr 19, 2016

You should just be able to do the following:

(render
  "{% for i in res %}
      {{i.a}}
      {{i.b}}
      {% for j in i.c %}
          {{j.aa}}
          {{j.bb}}
          {{j.cc}}
      {% endfor %}
  {% endfor %}"
  {:res
   [{:a "A1"
     :b "B1"
     :c [{:aa "AA1"
          :bb "BB1"
          :cc "CC1"}
         {:aa "AA2"
          :bb "BB2"
          :cc "CC2"}
         {:aa "AA3"
          :bb "BB3"
          :cc "CC3"}]}
    {:a "A2"
     :b "B2"
     :c [{:aa "AA11"
          :bb "BB11"
          :cc "CC11"}
         {:aa "AA21"
          :bb "BB21"
          :cc "CC21"}
         {:aa "AA31"
          :bb "BB31"
          :cc "CC31"}]}]})

=>
"
 A1
 B1

 AA1
 BB1
 CC1

 AA2
 BB2
 CC2

 AA3
 BB3
 CC3


 A2
 B2

 AA11
 BB11
 CC11

 AA21
 BB21
 CC21

 AA31
 BB31
 CC31

 "

@zuriar
Copy link
Contributor Author

zuriar commented Apr 20, 2016

Thanks, as I thought. Accessing nested structures works fine for non-dotted (that is, non Datomic) keywords but doesn't work for dotted even if the 'double dot' escape I added is used. However, the double-dotted notation does work for non-nested access.

I will have a dig and see why this may be. If you have any pointers to specific files/functions much appreciated. Expect another pull request in due course.

Thanks for your help,
Hugh

@yogthos
Copy link
Owner

yogthos commented Apr 20, 2016

Yeah, I thought your last pr would've addressed that, but maybe the for tag is working around it. Might be a good place to start. Thanks for spearheading this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants