0

I have two content types: Ingredients (Butter, Flour, ...) and Units of mesure (Cup, Tablespoon, ...).

Ingredients have Density field (e.g Flour, 0.53g/ml) and Units of mesure a Capacity field (e.g. Cup, 250ml).

Using views, I am stuck trying to create a table similar to:

==================================================
|               | Nodes of "Units of measure"    |
|------------------------------------------------|
| Nodes of      | Math calculation based on      |
| "Ingredients" | "Desnsity" and "Capacity" values
|               |                                |
|               |                                |
==================================================

For example:

==================================================
|         | Grams | Cup  | Tablespoon | Teaspoon |
|------------------------------------------------|
| Butter  | 100   | 0.44 | 7.05       | 21.16    |
| Flour   | 100   | 0.80 | 12.80      | 38.43    |
| ...     |       |      |            |          |
|                                                |
==================================================

I don't know how to generate such a table with two content types titles as rows and columns respectively.

Any help would be appreciated. Thanks!

EDIT:

  • I read about similar questions that use references and relationships, but this view should show all nodes of both content types. So, they don't need to be related.
  • Maybe Units of measure should be a Taxonomy instead of a content type? I am open to answers changing the scenario/context described. How would you create such a table with Drupal?
1

its very easy if contentypes are "entity reference" related, on "less important" contentype add an entityreference field and relate that node to "main contentype", in views add a relationship with your entityreference field, filter (not exposed) to display only "main contentype", and when adding fields to your view (now both contentypes fields are listed in drop menu field listings), specify if you use or not the relationship, for fields on "main contentype" do not use relationship, do it in all "less important contentype" fields. done.

  • I already read some solutions using References and Relationships but in this case, I need to combine every node of both content types in the view. I don't see the need of reference nodes between them, all references would be the same (all nodes of the main content type). Not using entity reference should be possible in my opinion. Thanks for your answer – chimos Jul 14 '17 at 9:08
  • your question is confusing, please try to explain more clear what you need, i do not undrestand: "I need to combine every node of both content types in the view." if you are printing "recipies" lets say a cake, would be: flour: 100g, 0.80 cup; next row: butter: 20g, 5 teaspoon, ...., i'm i wrong? – pinueve Jul 14 '17 at 16:38
  • Sorry about the confusion. I'm not trying to print recipes, I'm trying to print the table I'm showing in the question above. With "every node" I mean every ingredient, and every unit. That's why I don't need relationships within them. I need only a table with rows (all ingredients) and columns (all units) – chimos Jul 16 '17 at 7:15
  • 1
    I still do not understand your question, if contentypes are not related at all, in a view, you could filter by contentype and select both, first row will be from contentype A (nid=1), second row from B (nid=2), etc. there is no way to show "2 rows (2 nid's)" in a single row from different contentypes, i may be wrong but i think one contentype is not neccesary, just add all fields in a single contentype – pinueve Jul 17 '17 at 1:07
  • As if one content type is not necessary, I think you are right, I will try to get it done having each unit as Ingredients fields, it makes sense. Because of my requirements I was too stuck in my first ideas and wasn't able to get them adapted to Drupal nature. You helped a lot. Thank you! – chimos Jul 19 '17 at 9:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.