# Confusing documentation on Composers

**URL:** https://discourse.roots.io/t/confusing-documentation-on-composers/24411
**Category:** sage
**Tags:** sage10
**Created:** 2022-12-14T08:58:10Z
**Posts:** 5

## Post 1 by @www — 2022-12-14T08:58:11Z

Hello.  
I’m into learning “sage” and especially reading about Composers in the template context.  
It’s a somewhat obscure topic to me, but I’m holding fast.  
On my path to knowledge I stumbled upon this blog post:

> **[Composers | Sage Docs](https://roots.io/sage/docs/composers/)**
>
> Composers allow you to pass scoped data to views of any kind--templates, partials, etc.

And it sent me back into useless error loops - it is particularly misleading and doesn’t help learners at all as it’s literally giving non - working code samples.

Example:

```
// Composers/Header.php
namespace App\Composers;
```

What?  
I’ve read elsewhere ( [https://docs.roots.io/sage/10.x/composers/](https://docs.roots.io/sage/10.x/composers/) )  
that the namespace was `namespace App\View\Composers;`

```
use Roots\Acorn\View\Composer;
class Header extends Composer
{
    protected static $views = [
        'partials.header',
    ];

    public function with($data, $view)
    {
        return [
            'img_url' => get_attachment_image_url(get_post_thumbnail_id()),
            'class' => 'hero',
            'title' => $post->post_title,
        ];
    }
}
```

Some of the confusing points for this example alone,  
1- `get_attachment_image_url` isn’t a wordpress function  
2- `$post` is undefined in this context.  
3- ` public function with($data, $view)` or `public function with()` ?  
( `Method 'App\View\Composers\WhatEver::with()' is not compatible with method 'Roots\Acorn\View\Composer::with()'.`  
4- " Get it from `$data`"

> `$data` is the context as it exists when your view is `@include`ed. This means that any variable available to that view is available to your View Composer as well. `$data` is a keyed array, and the keys are the same as the variable names that can be used in the blade.

Nope, $data is undefined in this context.  
`$this->data->get('post')` is undefined.  
How are you exactly supposed to get WP\_post object values in that context?  
Sure you can use native WP functions but isn’t it a built-in object that I could use?

And so forth - maybe i’m missing something also -  
No pun intended but this single piece hold me back in a lot of errors and misunderstanding, and this post is to maybe avoid that pain to other new learners.

---

## Post 2 by @alwaysblank — 2022-12-14T14:45:15Z

Sorry for the problems you’re running into. That post is getting close to four years old at this point, and some of it (like the `$data` stuff) is outdated. The docs are what you should trust, and are currently a much better reference.

---

## Post 3 by @www — 2022-12-14T15:25:54Z

That is my point: it’s confusing for a beginner and hardens the learning curve.

What would you recommend using inside a composer to access current WP\_post object?  
I’m actually relying on native WP functions ( like `'ID' => get_the_ID()`, but is there an object like `$data` we can use, maybe I’m overdoing it?

---

## Post 4 by @evance — 2022-12-15T09:41:33Z

Getting started with Sage 10 and the View Composers I also went ahead with this guide only to later notice that some of the stuff is outdated…

I’d suggest to add a disclaimer on top of the post stating that some of the infos in the post aren’t accurate any more and the [docs should be consulted](https://docs.roots.io/sage/10.x/composers/).

Is that something you would be open for @alwaysblank?

---

## Post 5 by @ben — 2022-12-15T17:21:33Z

We’ve redirected that post to the docs page for now — thank you for bringing this to our attention!
