Element API access param in transformer Each of my entries has multiple categories (e.g. series, disciplines, and stages). I can get a list of elements related to a single category but I'd also like to get the category information as well (title, summary etc). Ideally, I'd like to pass the $slug to the transformer so I can grab the category from there, is that possible?

Here's my current code for an endpoint from elementapi.php

'api/series/&lt;slug:{slug}&gt;.json' =&gt; function($slug) {
  // get category by slug
  $series = craft()-&gt;elements-&gt;getCriteria(ElementType::Category);
  $series-&gt;group = 'series';
  $series-&gt;slug = $slug;
  $series-&gt;first();

  return [
    'elementType' =&gt; ElementType::Entry,
    'criteria' =&gt; [
      'section' =&gt; ['lessons'],
      'relatedTo' =&gt; ['targetElement' =&gt; $series]
    ],
    'transformer' =&gt; function(EntryModel $entry) {
      return structureEntry($entry);
    }
  ];
},

/*-------------------------------------------*/

function structureEntry($entry) {
  return [
    'id' =&gt; (int)$entry-&gt;id,
    'title' =&gt; $entry-&gt;title,
    'slug' =&gt; $entry-&gt;slug,
    'summary' =&gt; $entry-&gt;summary ? $entry-&gt;summary : null,
    'featuredImage' =&gt; $entry-&gt;featuredImage-&gt;first() ? getImageSizes($entry-&gt;featuredImage-&gt;first()) : null,
    'body' =&gt; $entry-&gt;body ? (string)$entry-&gt;body : null,
    'series' =&gt; $entry-&gt;series ? getCategoryData($entry-&gt;series) : null,
    'stage' =&gt; $entry-&gt;stage ? getCategoryData($entry-&gt;stage) : null,
    'disciplines' =&gt; $entry-&gt;discipline ? getCategoryData($entry-&gt;discipline) : null
  ];
}

function getCategoryData($categories) {
  $cats = array();

  for($i = 0; $i &lt; count($categories); $i++) {
    $cats[$i] = [
      'id' =&gt; (int)$categories[$i]-&gt;id,
      'title' =&gt; $categories[$i]-&gt;title,
      'slug' =&gt; $categories[$i]-&gt;slug,
      'summary' =&gt; $categories[$i]-&gt;summary
    ];
  }

  return $cats;
}


Ideally, I'd like to do something like this:

'api/series/&lt;slug:{slug}&gt;.json' =&gt; function($slug) {
  // get category by slug
  $series = craft()-&gt;elements-&gt;getCriteria(ElementType::Category);
  $series-&gt;group = 'series';
  $series-&gt;slug = $slug;
  $series-&gt;first();

  return [
    'elementType' =&gt; ElementType::Entry,
    'criteria' =&gt; [
      'section' =&gt; ['lessons'],
      'relatedTo' =&gt; ['targetElement' =&gt; $series]
    ],
    'transformer' =&gt; function(EntryModel $entry) {

      $category = craft()-&gt;elements-&gt;getCriteria(ElementType::Category);
      $category-&gt;group = 'series';
      $category-&gt;slug = $slug;
      $category-&gt;first();

      return array_merge(structureEntry($entry), structureCategory($category));
    }
  ];
},


Any help would be appreciated, thanks!
I managed to get access to the slug in the transformer function by using use. I'm not sure if it's the correct way but it works for now.

'api/series/&lt;slug:{slug}&gt;.json' =&gt; function($slug) {
  // get category by slug
  $category = craft()-&gt;elements-&gt;getCriteria(ElementType::Category);
  $category-&gt;group = 'series';
  $category-&gt;slug = $slug;
  $category-&gt;first();

  return [
    'elementType' =&gt; ElementType::Entry,
    'criteria' =&gt; [
      'section' =&gt; ['lessons'],
      'relatedTo' =&gt; ['targetElement' =&gt; $series]
    ],
    'transformer' =&gt; function(EntryModel $entry) use ($category) {

      $firstCategory = $category-&gt;first();

      $cat = [
        'id' =&gt; $firstCategory-&gt;id,
        'slug' =&gt; $firstCategory-&gt;slug,
        'title' =&gt; $firstCategory-&gt;title
      ];

      return array_merge(structureEntry($entry), structureCategory($cat));
    }
  ];
}