Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] Blade template @section behaves inconsistently #17679

Closed
axelitus opened this issue Jan 30, 2017 · 2 comments
Closed

[5.4] Blade template @section behaves inconsistently #17679

axelitus opened this issue Jan 30, 2017 · 2 comments

Comments

@axelitus
Copy link
Contributor

axelitus commented Jan 30, 2017

  • Laravel Version: 5.4.0
  • PHP Version: 7.1.0
  • Database Driver & Version: MySql 5.7.16

Description:

Before updating to the latest Laravel release, I had a template that inserted some styles through a @section('style', style_func('param')) and worked fine. After I updated this statement behaves oddly and instead of inlining the style where it should, it automatically places the escaped text inside <p></p> tag in the body. The odd thing is if I do:

@section('style')
style_func('param')
@endsection

it works fine...

As I am sending an email with this, the end result is having some content displayed in the email message and the styles are gone (I'm not using the resources/views/vendor/mail/html/themes/default.css file).

Steps To Reproduce:

For simplicity I will create a simple example.

<!-- email/master.php -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>@yield('title')</title>

    <!-- Styles -->
    @yield('style')
</head>
<body>
@yield('content')
</body>
</html>

And now scenario 1 (odd behavior):

<!-- email/registered_odd_behavior.php -->
@extends('email.master')

@section('title', 'User Registered')
@section('style', '<style> * { font-size: 20pt; } h1 { color: blue; } </style>')

@section('content')
<h1>User Registered</h1>
<p>Thanks for registering!</p>
@endsection

Result:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>User Registered</title>

    <!-- Styles -->
</head>
<body>
<p>
&lt;style&gt; * { font-size: 20pt; } h1 { color: blue; } &lt;/style&gt;
</p>
<h1>User Registered</h1>
<p>Thanks for registering!</p>
</body>
</html>

This is scenario 2 (which works "fine"):

<!-- email/registered_correct_behavior.php -->
@extends('email.master')

@section('title', 'User Registered')
@section('style')
<style> * { font-size: 20pt; } h1 { color: blue; } </style>
@endsection

@section('content')
<h1>User Registered</h1>
<p>Thanks for registering!</p>
@endsection

Result:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>User Registered</title>

    <!-- Styles --><style style="font-size: 20pt;"> * { font-size: 20pt; } h1 { color: blue; } </style>
</head>
<body>
<p>
&lt;style&gt; * { font-size: 20pt; } h1 { color: blue; } &lt;/style&gt;
</p>
<h1>User Registered</h1>
<p>Thanks for registering!</p>
</body>
</html>

The downside to scenario 2 is that in reality the style is given through a function call which does not work in neither case as the function is not processed as PHP even if I "cascade" a @php directive.

Is using the @section short-syntax doing something different on purpose? This should be documented somewhere over here Blade Templates, but I could not find anything regarding this.

I noticed the styles are being also automatically embedded in the code, is this a new behavior for emails/Mailables?

@axelitus axelitus changed the title [5.4] Blade template @section behaves oddly [5.4] Blade template @section behaves inconsistently Jan 30, 2017
@themsaid
Copy link
Member

That change was introduced 10 days ago and it was undocumented in the upgrade guide: #17453

Will open a docs PR to add it, thank you for reporting this :)

@axelitus
Copy link
Contributor Author

Thanks! That solves it! Important change, hopefully this makes the docs both in Upgrade Guide and in Blade Templates.

Makes me wonder also if a one-line unescaped @section syntax would be nice:

@section('style', {!! 'unescaped string' !!}) or something like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants