laravel-mail-editor icon indicating copy to clipboard operation
laravel-mail-editor copied to clipboard

View data object/array

Open robov opened this issue 5 years ago • 5 comments

Seems that the view data can only handle indiviudal variables, not objects or arrays

robov avatar May 26 '20 12:05 robov

Hi @robov, would it be possible to give more information and an example? Are these variables that are passed into the constructor of the Mailable class?

ReeceM avatar Jun 24 '20 08:06 ReeceM

Well, I just face this and still don't have any solution to do for each inside the email template. Every time I use @foreach, I always get this error Facade\Ignition\Exceptions\ViewException: syntax error, unexpected '&' (View: ...). It looks like it couldn't render <p>@foreach ($products-&gt;products as $product)</p>, but it works on one data.

ridwankustanto avatar Sep 06 '20 14:09 ridwankustanto

Well, I just face this and still don't have any solution to do for each inside the email template. Every time I use @foreach, I always get this error Facade\Ignition\Exceptions\ViewException: syntax error, unexpected '&' (View: ...). It looks like it couldn't render <p>@foreach ($products-&gt;products as $product)</p>, but it works on one data.

Aaaaand that was my fault. So I just figured this out. Looks like it couldn't render $products-&gt;products on foreach as I mentioned above, and I assign the products obj to new variable in the Mailable. Like this

`

public $data;
public $products;

public function __construct(Request $data)
{
    //

    $products = json_decode($data->products);

    // dd($products);

    $this->data = $data;
    $this->products = $products->products;

}

`

And you can use @foreach like usual on the mail template.

That's it. Idk if this is what you meant but I'm glad if I could help with this.

ridwankustanto avatar Sep 06 '20 15:09 ridwankustanto

Well, I just face this and still don't have any solution to do for each inside the email template. Every time I use @foreach, I always get this error Facade\Ignition\Exceptions\ViewException: syntax error, unexpected '&' (View: ...). It looks like it couldn't render <p>@foreach ($products-&gt;products as $product)</p>, but it works on one data.

Hi @ridwankustanto just as a side note to what you had, the &gt; should be filtered out in newer versions? Are you using the latest one?

ReeceM avatar Sep 06 '20 16:09 ReeceM

@ridwankustanto but I am glad that is sorted now.

In line with the original issue, I do believe it is inline with what you had, so thank you for sharing the issue that you had.

With regards handling the arrays, I do believe that that should possibly be solved. But that would need some checks to confirm that.

ReeceM avatar Sep 06 '20 16:09 ReeceM