简体   繁体   中英

Why does my Laravel app output html tags as string

I'm new to Laravel and trying to replicate the code from this site: Create your first laravel app , but the html tags are echoed as string instead of tags.

The site I'm using uses stuff like these:

<span class="nt">&lt;th&gt;</span>

and I dont know what it does. For example, the original @foreach line was:

@foreach($characters as $key =&lt; $value)

and Laravel was interpreting it as

<?php $__currentLoopData = $characters; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key =&gt; $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>`. i had to change =&lt; to => for the code to run..attached below is the welcome.blade.php code and a screenshot 




            @if(Auth::check())
              <span class="c">&lt;!-- Table --&gt;</span>
              <span class="nt">&lt;table</span> <span class="na">class=</span><span class="s">"table"</span><span class="nt">&gt;</span>
                  <span class="nt">&lt;tr&gt;</span>
                      <span class="nt">&lt;th&gt;</span>Character<span class="nt">&lt;/th&gt;</span>
                      <span class="nt">&lt;th&gt;</span>Real Name<span class="nt">&lt;/th&gt;</span>
                  <span class="nt">&lt;/tr&gt;</span>
                  @foreach($characters as $key => $value)
                    <span class="nt">&lt;tr&gt;</span>
                      <span class="nt">&lt;td&gt;</span>{{ $key }}<span class="nt">&lt;/td&gt;&lt;td&gt;</span>{{ $value }}<span class="nt">&lt;/td&gt;</span>
                    <span class="nt">&lt;/tr&gt;</span>
                  @endforeach
              <span class="nt">&lt;/table&gt;</span>
            @endif


    <span class="nt">&lt;/div&gt;</span>
    @if(Auth::guest())
      <span class="nt">&lt;a</span> <span class="na">href=</span><span class="s">"/login"</span> <span class="na">class=</span><span class="s">"btn btn-info"</span><span class="nt">&gt;</span> You need to login to see the list &gt;&gt;<span class="nt">&lt;/a&gt;</span>
    @endif
<span class="nt">&lt;/div&gt;</span>
<span class="nt">&lt;/div&gt;</span></div>
@endsection.

屏幕截图

That doesn't look right. I'm guessing it's a formatting mistake on the auth0 site.

If you have a look at that view template in the repo they provide, it doesn't contain the &lt and &gt , etc.

The CSS classes such as "nt" and "c" are classes that are used to do syntax highlighting on the code in the auth0 post. For example, in the screenshot below you'll see where the "nt" class was applied to the span element in which a div tag was displayed in a part of the code that was rendered correctly.

auth0帖子上语法突出显示的代码的屏幕截图

The &lt; 's and &gt; 's that you see are there to force the browser to render < and > , respectively, as text. If instead the characters < and > were used themselves, the browser would interpret them as html elements.

In this case, however, there seems to have been a formatting mistake on the part of the code that you posted on the auth0 side before they sent back the html to the browser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM