Recently I upgrade Laravel to 6.13.0. Before the upgrade, my markdown email template was good in design. After upgrade, I am trying to send Laravel Mail in markdown format. But when I test it with MailDev it is rendering HTML format.
My email template looks like.
#component('mail::message')
#component('mail::panel')
<div class="row">
<div class="col-6 bg-gray">
<span>Time</span>
</div>
<div class="col-6 bg-gray">
<span class="badge">{{ date('jS F g:ia', strtotime($signal->signal_time)) }}</span>
</div>
</div>
#endcomponent
#endcomponent
then its look like this in MailDev..
What can I do now?
I get the solution for this issue. recently Laravel has moved CommonMark as their markdown template. it doesn't convert space. what's why my email template is shown as HTML markup. Now, what has to do to fix it.
I removed all space from my email template files like this.
#component('mail::message')
#component('mail::panel')
<div class="row">
<div class="col-6 bg-gray">
<span>Time</span>
</div>
<div class="col-6 bg-gray">
<span class="badge">{{ date('jS F g:ia', strtotime($signal->signal_time)) }}</span>
</div>
</div>
#endcomponent
#endcomponent
and that fixed my issue. I think someone gets help from this answer.
Markdown considers indented stuff to be code blocks. So, we just have to de-indent everything.
Example:
#component('mail::message')
<h3>Hi {{ $name }}</h3>
<h2>You are invited to join as a member. Here is your login credentials:</h2>
<br>
<table>
<tr>
<td>Email</td>
<td>{{ $email }}</td>
</tr>
<tr>
<td>Password</td>
<td>{{ $password }}</td>
</tr>
</table>
#component('mail::button', ['url' => $url])
<span>Login Here</span>
#endcomponent
<h4>Thanks,</h4>
#endcomponent
I got the same issue and in my case, i have fixed it with writing all stuff with a # in one line, so as an example:
File: resources/views/vendor/notifications/email.blade.php
Before (not working, showing linkduration in mail):
#lang('mail.welcome.linkduration',
['linkduration' => $linkduration]
)
After (working)
#lang('mail.welcome.linkduration', ['linkduration' => $linkduration])
I hope, this will help
The default panel component strips HTML.
If you want to override the default mail:: component namespace you have to publish the vendor files.
php artisan vendor:publish --tag=laravel-mail
Then if you look in resources/views/vendor/mail/markdown/ you will see the comonents which you can edit.
panel.blade.php is just {{ $slot }}, change to {!! $slot !!} to allow unfiltered html.
Also, as a side note, if you are using Markdown, you probably don't want to be using complicated bootstrap & HTML directly anyway.
Read more here: https://laravel.com/docs/6.x/mail#customizing-the-components
Related
i have been trying to show an image that i already stored on a folder and stored the path in the database, i need to show it on the edit page that i created using the infyom CRUD generator.
Been trying like this and even adding the img tag but it just displays the broken image
<!-- Product Image Field -->
<div class="form-group col-sm-6">
{!! Form::label('product_image', 'Imagen:') !!}
{!! Html::image('product_image') !!}
{{ HTML::image(Storage::url('product_image')) }}
{!! Form::file('product_image') !!}
</div>
<div class="clearfix"></div>
any tips / hints or help on this is greately appreciated. thanks
Hello #SolarConfinement Vishal Here from InfyOm and we are not supporting image Right now using CRUD generator thanks.
But you can get you image path and show it into blade.
I would like to render a simple plain-text or html output in my twig template ( page--front.htmltwig ).
I have this kind of HTML :
<header class="intro-header" style="background-image: url('themes/custom/tommiecrawford/images/home-bg.jpg')">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="site-heading">
{{ HERE I WANT TO RENDER SOME HTML FROM DRUPAL }}
<hr class="small">
<span class="subheading">A Clean Blog Theme by Start Bootstrap</span>
</div>
</div>
</div>
</div>
What is the best way to create a simple html output in drupal and then render it in this twig template?
Do i need to create a custom block or something like that? And how can i render this in the template so i can make the output dynamic?
Many thanks
Alright, i found out how the template system actually works.
You need to enable twig debug to see what template is used. In this case it was block--slogan.html.twig.
So i just need to overwrite that template in mine custom templates directory.
After that i just could use the {{ content }} method to display the block content and style it a little bit.
I did a redirect in laravel:
return redirect('admin')->with($returnData);
$returnData is a string that contains a bootstrap info div with the result from the controller. Almost everything is working except when the page loads again it shows the html on the page as if it were text, brackets and everything. If I use this:
#if(!empty(Session::get('error'))) {{ Session::get('error')}} #endif
Then it shows is as pure text. If I change it to
<?php if(!empty(Session::get('error'))) { echo Session::get('error'); } ?>
It works fine. Im ok keeping it like this but I would rather utilize Blade / Laravel as its supposed to be used so I was wondering if there is a way to have the #if statement show the rendered html and not the text version?
I would recommend returning just the error message then in your view create the div. So if you were to change the layout of the view, you would it in one place.
#if(Session::has('error'))
<div class="alert alert-danger">
{{ Session::get('error')}}
</div>
#endif
hope this help.
To show the rendered HTML you should use {!! $variable->coontent !!} in your view, and this gonna convert your HTML text to render
May this example will help you.
Try this
#if (session('Error'))
<div class="alert alert-success">
{{ session('Error') }}
</div>
#endif
If you want to display plain text from error without any HTML entities you can simply use:
{{ Session::get('error') }}
or
{{ session('error') }}
If you have HTML entities in your variable then use:
{!! Session::get('error') !!}
Try changing your blade code to following.
#if(!empty(Session::get('error')))
{!! Session::get('error') !!}
#endif
I'm rendering a page that is primarily a form with view::make in Laravel and it is crashing, causing ERR_CONNECTION_RESET. After a long investigation and many red herrings, I started erasing (not commenting) random sections out of the blade file for the view and realized that if I
a) erase 2 of the {{Form}} calls inside this section of the form
b) remove the {{-- and --}} from around this section of the form
{{--
<div class="form-row">
{{ Form::label('foo', 'foo:') }}
{{ Form::text('foo') }}
</div>
<div class="form-row">
{{ Form::label('foo', 'foo:') }}
{{ Form::text('foo') }}
</div>
<div class="form-row">
{{ Form::label('foo', 'foo') }}
{{ Form::text('foo') }}
</div>
--}}
the page will render. I am not sure what exactly the cause here is. There are other blocks above and below, although this is a 3-div commented out section which none of the others are.
Anyone have a clue what is causing this? Running on WAMP if that matters.
Blade comments should only be used for simple remarks or to comment out single-line Blade functions. A single Blade comment cannot be used to comment out multiple lines of code.
Use PHP Block Comments instead. They are still usable in a blade.php file
<?php /*
{{ HTML::form("foo") }};
{{ HTML::form("bar") }};
*/ ?>
Alternatively, comment out your Blade one line at a time:
{{-- HTML::form("foo") --}};
{{-- HTML::form("bar") --}};
Examples of Valid Blade Comments:
Single Blade Function:
{{-- Form::text('foo') --}}
Remark:
{{-- Form Section 1 --}}
Examples of Invalid Blade Comments:
Incorrect syntax:
{{-- Form::text('foo') -- }}
"#" Inside of Blade comment
{{-- #Form::text('foo') --}}
Nested PHP:
{{-- <?php
echo "foo";
echo "bar
?> --}}
Nested Blade:
{{--
{{ HTML::form("foo") }};
{{ HTML::form("bar") }};
--}}
Internals:
Using the sample code from the question, Laravel's Blade Compiler will generate a temporary PHP file containing the following PHP and HTML:
<?php /*
<div class="form-row">
<?php echo Form::label('foo', 'foo:'); ?>
<?php echo Form::text('foo'); ?>
</div>
<div class="form-row">
<?php echo Form::label('foo', 'foo:'); ?>
<?php echo Form::text('foo'); ?>
</div>
<div class="form-row">
<?php echo Form::label('foo', 'foo'); ?>
<?php echo Form::text('foo'); ?>
</div>
*/ ?>
The Blade code inside of the Blade comments are still parsed into PHP. The PHP end tags inside of the PHP block-comment can cause compilation issues:
?> breaks out of PHP mode and returns to HTML mode, and // or #
cannot influence that.
Comments in Blade are very simple!
{{-- Blade comments that wil not appear in the rendered HTML output --}}
You can either do normal PHP comments:
<? /* some comment here */
// or single line comments
# or these :)
?>
I have same problem with laravel 5.1 and PHP 7 (new homestead). The work around was to use this:
<?php /* XXX */?>
instead of this:
{{-- XXX -- }}.
I have a similar symptom and it seems to be related to the length of the comment alone. I tested it with a comment that doesn't contain any PHP code or blade statements at all:
{{--
0123456789abcdef
0123456789abcdef
0123456789abcdef
--}}
I kept adding copies of the repeated line until it crashed. The comment was lexically followed by a blade #if statement, and the corresponding <php if(...): ?> did not end up in the compiled template, but the closing <?php endif; ?> did, resulting in a syntactically invalid compiled template.
It seems to be a bug in the blade compiler and I will report it.
The workaround is to split long blade comments with --}}{{--.
I have Tried the
Nested PHP:
{{-- <?php
echo "foo";
echo "bar";
?> --}}
#TonyArra
While using . It is Not Commenting the Content and prevents from Compiling as HTML
and this is the htmlsource
{{-- foobar --}}
Which i have got
Thats Because If You want To Comment the php Code inside Blade
Try this
<!-- #php echo 'hai'; #endphp -->
OR
<!-- <?php echo 'hai'; ?> -->
and try to view the page source
Blade comments like this one, were the problem in my case:
{{--
#if ($test)
<div>something</div>
#else
<div>something else</div>
#endif
--}}
Simply we have to use a double curly bracket followed by a double hyphen.
This will work for the single line as well multiple lines.
{{-- --}}
Blade Comments
{{-- This comment will not be present in the rendered HTML --}}
Referene: https://laravel-news.com/laravel-blade-comments
I created a filter in Twig that wraps some HTML around the output. E.g.
{{ 'this is a "test"'|display }}
outputs
<div id="container">
<div id="content">
this is a "test"
</div>
<div id="toolbar">
edit
</div>
</div>
The dilemma is, I would like that subsequent filters are applied only on the original content, and not on the entire html. E.g.
{{ 'this is a "test"'|display|upper|e }}
outputs
<DIV ID="CONTAINER">
<DIV ID="CONTENT">
THIS IS A "TEST"
</DIV>
<DIV ID="TOOLBAR">
<A HREF="/EDIT.PHP">EDIT</A>
</DIV>
</DIV>
but as you can imagine, I would prefer the output like this
<div id="container">
<div id="content">
THIS IS A "TEST"
</div>
<div id="toolbar">
edit
</div>
</div>
Changing the filter order to
{{ 'this is a "test"'|upper|e|display }}
would work for the upper filter, but not for the escape filter, because it places itself always at the end of the filter queue. Also it should work with autoescape=true.
Reading the twig documentation, I can't find a standard way to do what I want. Has someone maybe tried something similar? Or has someone an idea to work around the problem?
Thanks in advance!
Try:
{{ 'this is a "test"'|upper|e|display }}
Filter your content in first place and then wrap it.