2013-08-19 1 views
1

Вот что я пытаюсь сделать (мой код):клинка смешивается с PHP не работает

@extends('base') 
@section('title', 'Quests') 
@stop 
@section('main') 

<? $quests = array ( 
    1 => array ("name" => "Quest 1", "level" => 100, "description" => "Write your description here", "reward" => "Shield, Boots"), 
    2 => array ("name" => "Quest 2", "level" => 100, "description" => "4 Peoples needed!", "reward" => "Sword, Stonecutter Axe, Armor, Present(choose 1)"), 
    3 => array ("name" => "Inferno Quest", "level" => 100, "description" => "Very hard quest. You need a big team to do this quest, the quest is long too!", "reward" => "bla bla") 
); 

?> 

<div id="spaceholder">&nbsp;</div> 
<div class="container"> 
    <div class="doc-content-box"> 
     <legend>Quests</legend> 
     <p>The quests listed below are not all the quests on the server, there are many many other quests, but these are the ones with experience bonus. The expeirence bonus rewarded from quests is multiplied with your current experience stage.</p> 
     <table class="table table-striped"> 
      <thead> 
       <tr> 
        <th>Quest</th> 
        <th style="width: 70%">Notes</th> 
       </tr> 
      </thead> 
      <tbody> 
       <? foreach($quests as $quest) 
       echo '<tr> 
        <td> 
         <strong>' . $quest['name'] . '</strong><br> 
         <span class="label label-success">Experience bonus: 100 000</span><br> 
         <span class="label label-important">Level requirement: 35</span><br> 
        </td> 
        <td>This quest requires completing all missions.</td> 
       </tr>'; 
       ?> 
      </tbody> 
     </table> 
    </div> 
@stop 

Выход таков:

  1. Первые массивы из квест отображаются как обычный текст (код)
  2. Название квеста отображается также как обычный текст (код)

Если это все-таки можно сделать с Laravel, я хотел бы знать.

+0

Имя вашего файла вида должно заканчиваться: '.blade.php', чтобы шаблон Blade работал в Laravel. –

+0

@RubensMariuzzo это .. это называется quests.blade.php –

+0

, когда вы сказали, что ваш массив отображается как обычный текст, как он выглядит? –

ответ

5

Вместо использования <? и ?>, используйте <?php и ?>. Это заставило меня поправиться в моих CodeIgniter.

Я также предпочел бы использовать петлю foreach лезвие.

@extends('base') 
@section('title', 'Quests') 
@stop 
@section('main') 

<?php 
$quests = array ( 
    1 => array ("name" => "Quest 1", "level" => 100, "description" => "Write your description here", "reward" => "Shield, Boots"), 
    2 => array ("name" => "Quest 2", "level" => 100, "description" => "4 Peoples needed!", "reward" => "Sword, Stonecutter Axe, Armor, Present(choose 1)"), 
    3 => array ("name" => "Inferno Quest", "level" => 100, "description" => "Very hard quest. You need a big team to do this quest, the quest is long too!", "reward" => "bla bla") 
); 

?> 

<div id="spaceholder">&nbsp;</div> 
<div class="container"> 
    <div class="doc-content-box"> 
     <legend>Quests</legend> 
     <p>The quests listed below are not all the quests on the server, there are many many other quests, but these are the ones with experience bonus. The expeirence bonus rewarded from quests is multiplied with your current experience stage.</p> 
     <table class="table table-striped"> 
      <thead> 
       <tr> 
        <th>Quest</th> 
        <th style="width: 70%">Notes</th> 
       </tr> 
      </thead> 
      <tbody> 
       @foreach($quests as $quest) 
        <tr> 
         <td> 
          <strong>{{$quest['name']}}</strong><br> 
          <span class="label label-success">Experience bonus: 100 000</span><br> 
          <span class="label label-important">Level requirement: 35</span><br> 
         </td> 
         <td>This quest requires completing all missions.</td> 
        </tr> 
       @endforeach 
      </tbody> 
     </table> 
    </div> 
@stop 

Я использую подобный метод для своего проекта, он работает.