Answers.Body: <p>If you want to show all ingredients related to the current entry you'd use the Single Entry Endpoint to pass the entry into the <code>relatedTo</code> param.</p>
  
  <pre><code>'ingredients/&lt;entryId:\d+&gt;.json' =&gt; function($entryId) {
    return [
      'elementType' =&gt; 'Entry',
      'criteria' =&gt; [
          'section' =&gt; 'ingredients',
          'relatedTo' =&gt; $entryId
      ],
      'transformer' =&gt; function(EntryModel $entry) {
        return [
          'title' =&gt; $entry-&gt;title,
          'url' =&gt; $entry-&gt;url
        ];
      },
    ];
  },
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-02T13:38:57.017Z
Answers.Text: If I understand correctly here we've returned an array of all related entries titles per single entry from section _ingredients_.  Now I'm thinking how this should point me in the right direction when I'd like to show related entries from the _ingredients_ section of a current entry.
Answers.UserDisplayName: Dominik Krulak
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-02T13:51:22.747Z
Answers.Text: I expect I failed to understand your original requirements. Can you update your original question with some more details about the site's structure and the entry you're talking about? Is the entry you're outputting these ingredients on also a related entry of an ingredient?
Answers.UserDisplayName: Luke Pearce
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-02T13:53:36.143Z
Answers.Text: I'm on it right now and thanks for the grammar :) @Luke Pearce
Answers.UserDisplayName: Dominik Krulak
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-02T14:40:52.283Z
Answers.Text: This question links me to [this question](http://craftcms.stackexchange.com/questions/11354/passing-multiple-parameters-to-the-element-api)
Answers.UserDisplayName: Dominik Krulak
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-02T15:06:47.300Z
Answers.Text: Updated my original answer. This will return all ingredients related to the entry of whose ID you use in the endpoint.
Answers.UserDisplayName: Luke Pearce
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-02T15:45:59.410Z
Answers.Text: Sorry for the late update on your answer. I was trying to comprehend it. Thank you @Luke Pearce, it works :)
Answers.UserDisplayName: Dominik Krulak
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-02T11:54:40.767Z
Answers.LastActivityDate: 2016-08-02T15:05:11.903Z
Answers.LastEditDate: 2016-08-02T15:05:11.903Z
Answers.UserDisplayName: Luke Pearce
Body: <p>By following the <a href="https://github.com/pixelandtonic/ElementAPI#examples" rel="nofollow">ElementAPI plugin documentation</a> I was able to set up pagination of entries from the <em>ingredients</em> section on an entry page. Entries from the <em>ingredients</em> section have a relation field called <em>relatedEntries</em>.</p>
  
  <p>Sections structures involved - set as an example:</p>
  
  <ol>
  <li><em>ingredients</em></li>
  <li><em>drinks</em></li>
  </ol>
  
  <p><strong>Desired output would be to show entries related to currently loaded entry from <em>drinks</em> section.</strong></p>
  
  <p>So when I'm at <em>site.com/drink-entry-alfa</em> I'd like to display all related entries from section <em>ingredients</em> to that current entry.</p>
  
  <p>Using Twig I'd request current <code>entry.id</code> and use the <code>.relatedTo()</code> parameter to get related entries.</p>
  
  <p>Here is the example from ElementAPI's documentation:</p>
  
  <pre><code>&lt;?php
  namespace Craft;
  
  return [
    'endpoints' =&gt; [
      'ingredients.json' =&gt; [
        'criteria' =&gt; ['section' =&gt; 'ingredients'],
        'elementsPerPage' =&gt; 10,
        'transformer' =&gt; function(EntryModel $entry) {
          return [
            'title' =&gt; $entry-&gt;title
          ];
        },
      ],
    ],
  ];
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-02T14:23:53.343Z
Comments.Text: So you'd like to only show ingredients related to the current entry? Or you want to show all ingredients and if that ingredient is related to the current entry you want to get all entries related to that ingredient? Can you add an example of the structure using Drink A, B, C etc and Ingredient A, B, C?
Comments.UserDisplayName: Luke Pearce
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-02T14:31:35.207Z
Comments.Text: Just to show ingredients related to the current entry.
Comments.UserDisplayName: Dominik Krulak
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-02T14:38:42.080Z
Comments.Text: Also, @Luke Pearce you can see a little demonstration bellow the bold section in this question.
Comments.UserDisplayName: Dominik Krulak
Tags: <plugin-elementapi>
Title: Display related entries on entry page using ElementAPI
ThreadText: # Display related entries on entry page using ElementAPI
  
  (Asked by: username_0 on 2016-08-02)
  
  By following the [ElementAPI plugin documentation](https://github.com/pixelandtonic/ElementAPI#examples) I was able to set up pagination of entries from the *ingredients* section on an entry page. Entries from the *ingredients* section have a relation field called *relatedEntries*.
  
  Sections structures involved - set as an example:
  
  1. *ingredients*
  2. *drinks*
  
  **Desired output would be to show entries related to currently loaded entry from *drinks* section.**
  
  So when I'm at *site.com/drink-entry-alfa* I'd like to display all related entries from section *ingredients* to that current entry.
  
  Using Twig I'd request current `entry.id` and use the `.relatedTo()` parameter to get related entries.
  
  Here is the example from ElementAPI's documentation:
  
  ```
  <?php
  namespace Craft;
  
  return [
    'endpoints' => [
      'ingredients.json' => [
        'criteria' => ['section' => 'ingredients'],
        'elementsPerPage' => 10,
        'transformer' => function(EntryModel $entry) {
          return [
            'title' => $entry->title
          ];
        },
      ],
    ],
  ];
  
  ```
  
  **Tags:** plugin-elementapi
  
  > **Comments:**
  > **username_1**: So you'd like to only show ingredients related to the current entry? Or you want to show all ingredients and if that ingredient is related to the current entry you want to get all entries related to that ingredient? Can you add an example of the structure using Drink A, B, C etc and Ingredient A, B, C?  
  > **username_0**: Just to show ingredients related to the current entry.  
  > **username_0**: Also, @username_1 you can see a little demonstration bellow the bold section in this question.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-08-02. Score: 2 | Accepted answer
  
  If you want to show all ingredients related to the current entry you'd use the Single Entry Endpoint to pass the entry into the `relatedTo` param.
  
  ```
  'ingredients/<entryId:\d+>.json' => function($entryId) {
    return [
      'elementType' => 'Entry',
      'criteria' => [
          'section' => 'ingredients',
          'relatedTo' => $entryId
      ],
      'transformer' => function(EntryModel $entry) {
        return [
          'title' => $entry->title,
          'url' => $entry->url
        ];
      },
    ];
  },
  
  ```
  
  > **Comments:**
  > **username_0**: If I understand correctly here we've returned an array of all related entries titles per single entry from section _ingredients_.  Now I'm thinking how this should point me in the right direction when I'd like to show related entries from the _ingredients_ section of a current entry.  
  > **username_1**: I expect I failed to understand your original requirements. Can you update your original question with some more details about the site's structure and the entry you're talking about? Is the entry you're outputting these ingredients on also a related entry of an ingredient?  
  > **username_0**: I'm on it right now and thanks for the grammar :) @username_1  
  > **username_0**: This question links me to [this question](http://craftcms.stackexchange.com/questions/11354/passing-multiple-parameters-to-the-element-api)  
  > **username_1**: Updated my original answer. This will return all ingredients related to the entry of whose ID you use in the endpoint.  
  > **username_0**: Sorry for the late update on your answer. I was trying to comprehend it. Thank you @username_1, it works :)  
  
  ---
  
  