Skip to content

[7.x] Make attributes available within render method#32978

Merged
taylorotwell merged 3 commits into
7.xfrom
attributes-in-render
May 26, 2020
Merged

[7.x] Make attributes available within render method#32978
taylorotwell merged 3 commits into
7.xfrom
attributes-in-render

Conversation

@taylorotwell

@taylorotwell taylorotwell commented May 26, 2020

Copy link
Copy Markdown
Member

Currently $this->attributes is null within a component's render method. This solves that by allowing components to return a Closure from render to defer the template building... which allows you to do some pretty funky stuff.

public function render()
{
    return function ($data) {
        // return $data['attributes'];
        // return $this->attributes;
    };
}

@taylorotwell taylorotwell merged commit a2668ed into 7.x May 26, 2020
@GrahamCampbell GrahamCampbell changed the title Make attributes available within render method [7.x] Make attributes available within render method May 27, 2020
@driesvints driesvints deleted the attributes-in-render branch May 27, 2020 11:19
@Pennywise96

Copy link
Copy Markdown

Hello,
how can I get this to work?

If I put the return function ($data) in my component render function, I get this error:
syntax error, unexpected '}', expecting ';'

Did I forget something there?

@driesvints

Copy link
Copy Markdown
Member

@Pennywise96 this hasn't been released yet. Next Tuesday it will be.

@Pennywise96

Copy link
Copy Markdown

@driesvints I have now updated to version 7.14.0, but I still get the same error.
Did I forgot something?

@mennovanhout

Copy link
Copy Markdown

@driesvints I have now updated to version 7.14.0, but I still get the same error.
Did I forgot something?

As your error states. You're just using it wrong it seems. Probably you made a syntax error, But your snippet is to small to give any more details.

@Pennywise96

This comment has been minimized.

@BrandonSurowiec

This comment has been minimized.

@laravel laravel locked as off-topic and limited conversation to collaborators Jun 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants