[Cppcms-users] Accessing sub collections in a <% foreach %> loop
Brought to you by:
artyom-beilis
|
From: Ronnie C. <ron...@db...> - 2013-11-18 09:35:05
|
Hi I'm trying to achieve the following piece of functionality. I have a std::map with some keys, and a 2nd map with more keys. If the 2nd map has a key from the first map then I want to iterate over the values. I've done the following which works but is a bit hackish. I created a tmp variable that's assigned per loop so that it can be accessed from the foreach. Ideally I'd want to get rid of the C++ section completely. I'm guessing there probably is a way but I've just missed it Any thoughts? My Content looks like // Fields std::map<std::string,std::vector<std::string>> rms_fields; std::map<std::string,std::vector<std::string>> xdb_fields; // Tmp needed for cppcms foreach std::vector<std::string> tmp_fields; And tmpl file <% foreach pair in rms_fields %> <% item %> <!-- If field is in both rms and xdb then display across --> <% if (content.xdb_fields.find(pair.first) == content.xdb_fields.end()) %> <tr><td><%= pair.first %> </td> <% foreach field in pair.second %> <% item %> <td><%= field %></td> <% end %> <% end %> <td>-></td> <td>XDB Trade</td> </tr> <% else %> <!-- Display the RMS fields first --> <tr><td><%= pair.first %> </td> <% foreach field in pair.second %> <% item %> <td><%= field %></td> <% end %> <% end %> <td>-></td> <!-- Then the XDB fields, I create a temporary variable in my content data structure in order to be able to access it here but really I was to use it as a value in the "in" statement of the foreach below. --> <% c++ content.tmp_fields = content.xdb_fields.find(pair.first)->second; %> <% foreach field in tmp_fields %> <% item %> <td><%= field %></td> <% end %> <% end %> </tr> <% end %> <% end %> <% end %> Thanks Kind Regards Ronnie |