【问题标题】:Why does my Laravel app output html tags as string为什么我的 Laravel 应用程序将 html 标签输出为字符串
【发布时间】:2019-04-12 23:06:52
【问题描述】:

我是 Laravel 的新手,并试图从这个站点复制代码:Create your first laravel app,但 html 标签被回显为字符串而不是标签。

我正在使用的网站使用以下内容:

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

我不知道它是做什么的。例如,原来的@foreach 行是:

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

而 Laravel 将其解释为

<?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.

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    看起来不太对劲。我猜这是 auth0 网站上的格式错误。

    如果您在他们提供的repo 中查看该视图模板,它不包含&amp;lt&amp;gt 等。

    "nt""c" 等 CSS 类是用于对 auth0 帖子中的代码进行语法高亮的类。例如,在下面的屏幕截图中,您将看到"nt" 类应用于span 元素的位置,其中div 标记显示在正确呈现的部分代码中。

    您看到的&amp;lt;&amp;gt; 用于强制浏览器将&lt;&gt; 分别呈现为文本。如果改为使用字符 &lt;&gt; 本身,浏览器会将它们解释为 html 元素。

    但是,在这种情况下,您在 auth0 端发布的部分代码在将 html 发送回浏览器之前似乎存在格式错误。

    【讨论】:

    • 非常感谢。所以整个 到底是什么?...只是好奇
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-01
    • 2017-06-12
    • 1970-01-01
    • 1970-01-01
    • 2013-08-14
    • 2021-11-04
    相关资源
    最近更新 更多