New topic Closed topic
avatar image
1
Group records with Liquid
By Created , last editted

Hey,


I've got the following models with relations:


Each Project Location has 1 or many Project Activities ( Has and Belongs to Many relation), each Project Activity requires 1 or many Articles and of each Article you might need more then one. That's where the Project Activity Article model come is place.


Using Liquid, I'm looking for an output that shows the total amount of an article per location, like this:

Each Project Location can have multiple Project Activities where each of those Activities can require the same Article. I like to show each Article only once per Project Location and a sum of the amount. 


What collections do I need to prepare in Betty Blocks to send as variable to the template and how do I group and loop them to be able to create a table like the above? 


Can this be done without having a relation between Project Location and Project Activity Article or without creating an extra model that is populates in Betty by an action?


The Liquid that I have so far groups the Articles per Activity, not per Project Location. The json filter is to quickly show the content of the objects:

{% for project_location in project_locations %}
<hr />
{{project_location.planned_date_route}} - {{project_location.location.name}}<br /><br />
{% assign group = project_location.project_activities | group: "project_activity_articles" %}
{{group | json}}<br /><br />
{% endfor %}



Hey,


I've got the following models with relations:


Each Project Location has 1 or many Project Activities ( Has and Belongs to Many relation), each Project Activity requires 1 or many Articles and of each Article you might need more then one. That's where the Project Activity Article model come is place.


Using Liquid, I'm looking for an output that shows the total amount of an article per location, like this:

Each Project Location can have multiple Project Activities where each of those Activities can require the same Article. I like to show each Article only once per Project Location and a sum of the amount. 


What collections do I need to prepare in Betty Blocks to send as variable to the template and how do I group and loop them to be able to create a table like the above? 


Can this be done without having a relation between Project Location and Project Activity Article or without creating an extra model that is populates in Betty by an action?


The Liquid that I have so far groups the Articles per Activity, not per Project Location. The json filter is to quickly show the content of the objects:

{% for project_location in project_locations %}
<hr />
{{project_location.planned_date_route}} - {{project_location.location.name}}<br /><br />
{% assign group = project_location.project_activities | group: "project_activity_articles" %}
{{group | json}}<br /><br />
{% endfor %}


Answers
Sort by:

This topic is closed.