Laravel Mail not rendering properly - php

I have the issue in which when I am writing the components in Laravel Mailable, according to their 6.x documentation (since my Laravel version is 6.0). But despite that, in the actual email some components render properly, some are just plain HTML. By plain HTML I mean the text literally says <a>...</a>, but doesn't render the actual element.
Why would that be? Maybe there is a bug, or I am missing something? I have written the most regular email with the components provided by Laravel's docs. There is no linter errors. The view is written in blade btw.
#section('content')
#foreach ($paragraphs as $item)
<p> {{ $item }} </p>
#endforeach
#component('mail::button', [ 'url' => $link ])
{{ $buttonText }}
#endcomponent
#endsection

I resolved the issue. The issue disappeared when I removed any possible indentation in the file.
When every single line started at column 0, the components rendered properly.
Documentation (at least 6.x) doesn't say anything about that, so I assume this is a bug with blade/php mailing compilation or something.

Related

php echo stops rendering the page half way while laravel blade template works fine

I have a mcqs website, the problem is that when i try to load a quiz page with multiple questions and their answers, it loads fine.
Working code:
#foreach ($question->answers as $answer)
<span style="display:inline-block">
{{$answer->content}}
</span>
#endforeach
Not Working Code:
#foreach ($question->answers as $answer)
<span style="display:inline-block">
{!! $answer->content !!}
</span>
#endforeach
{!! $answer->content !!} is the same as echo $answer->content
however for the same code when i try to render the answers with HTML formatting using <?php echo , the page stops rendering midway. forexample if say the page was to load 30 questions , it will only load 10 and stops rendering . Even when i tried using {!!$answer->content!!} , the problem remains the same.
Note: i am returning set of questions using the below code:
$questions = Question::all()->where('exam_id',$exam_id)->random($questionsCount)->shuffle();
return view('quiz',compact('exam','questions','questionsCount','t'));
I have one to many relationship setup so i can extract the answers of the question using $question->answers
it works fine when i don't echo any answer content.
Anyhelp will be greatly appreciated. Thanks!
Looks like an issue with unescaped text. When you use the blade template's escape method ({{ }}) it is successful. When you use the unescaped method, ({!! !!}) it fails. This is the same when using the unescaped php echo.
There is likely some type of character in one of your questions that is causing a break of the loop or php echo.
To fix, use the blade escape {{ }} or php escape (htmlentities(), htmlspecialchars() etc) in the echo.
htmlentities-vs-htmlspecialchars is worth checking out as well.

how show text form contact.blade.php in the message in laravel

I makes website by laravel as multi language
and I make full switches to change the language and it work as the flowing code
<?php
return [
'home_menu'=>'home',
'about_menu'=>'about',
'contact_menu'=>'contact',
'message'=>'<h1> welcoome</h1>',
];
Now I need to show text from contact.blade.php from resource/views Instead of
welcoome.
There are many ways you can show your translations in Laravel
{{ trans(filename.arrayIndex) }}
#lang(filename.arrayIndex)
and in case you have html in your translations then
{!! trans(filename.arrayIndex) !!}
I hope this will help you but you must check all the Laravel documentation before starting the project. It will really help you understanding the Lara Concept better

How to conditionally escape values in Slim and Twig?

Code
We have the following Twig HTML template:
<div id="error">{{ flash.error | raw }}</div>
and we flash messages in multiple places, e.g.:
$app->flash('error', "Some error with this $user_supplied string.");
$app->flash('error', "Hello, <b>World</b>!");
Question
This is obviously a security concern, $user_supplied could include javascript. I would like to replace {{ flash.error | raw }} with {{ flash.error }}, while still allowing HTML in some cases.
What I would like to have:
<div id="error">{{ flash.error }}</div>
----
$app->flash('error', "Some error with this $user_supplied string.");
$app->flash('error', HTML("Hello, <b>World</b>!"));
That way all developers realize the dangers. I can probably hack this together, but is there maybe already a built-in way or a better alternative?
Hm, Perhaps you can check the contents of the variable in the PHP code before you pass it to the template. Then use some of PHP's built in string parsing functions to check the variable for the existence of certain tags.
If (for example) script tags are found, you could set the variable to null or false and then handle that value in your template.
Another way I can think of is to use the striptags filter. You define your allowed tags and what isn't defined will be removed. This way you can output what you want and only keep your allowed tags.
https://twig.symfony.com/doc/2.x/filters/striptags.html
{% set some_var = '<b><script>console.log(123)</script></b>' %}
<div id="error">{{ some_var|striptags('<b><strong>')|raw }}</div>
You can use escape twig variable for specific needs.
{{ flash.error|escape('js') }}
The escape filter supports the following escaping strategies:
html, js, css, url, html_attr
You can do this in your twig configuration, without knowing much about your project I am going to assume you are using Twig View. At the point of configuring Twig View for your Slim project you can do the following:
$view = new \Slim\Views\Twig('path/to/templates', [
'cache' => 'path/to/cache',
'autoescape' => 'js'
]);
That should have it configured globally for JS only escaping. I have not tested this so I am not sure if it works.

PHP Laravel blade template

I dont have knowledge in laravel Blade and I have this code :
<span v-bind:class="{ 'total': (listing.price_per_week), 'total total-center': (!listing.price_per_week)}">#{{ listing.price_view }}*</span>
I want to pass that price value to this function
<?php echo removeFrom( #{{ listing.price_view }} ); ?>
but it doesnt work this way
how can pass this
Thanks
Please check this out: Blade & JavaScript Frameworks
Since many JavaScript frameworks also use "curly" braces to indicate a
given expression should be displayed in the browser, you may use the #
symbol to inform the Blade rendering engine an expression should
remain untouched. For example:
<h1>Laravel</h1>
Hello, #{{ name }}.
In this example, the # symbol will be removed by Blade; however, {{
name }} expression will remain untouched by the Blade engine, allowing
it to instead be rendered by your JavaScript framework.

Laravel Multi js Include

I am new to Laravel so my problem is that I am trying to add multiple script files to my blade.php page using this code:
{{
HTML::script('js/bootstrap.min.js');
HTML::script('js/Chart.js');
}}
without any results , am I doing anything wrong or misunderstood some concept, please specify the best way to achieve my goal
only first include is working, the second one is not including
Thanks
You can't have line breaks inside Blade tags (at least not in Laravel 3). What you need to do is to add {{ ... }} for every HTML:: you have.
{{ HTML::script('js/bootstrap.min.js'); }}
{{ HTML::script('js/Chart.js'); }}

Categories