Вопрос

This is my Controller:

class HomeController extends BaseController {

public $layout = 'default';

public function index()
{
    $page = Page::find(1);
    $this->layout->page_title = $page->page_title;


    $allPages = Page::lists('title');
    // Give the page it's needed content
    $this->layout->nest('content', 'pages.home', array(
        'pageHeading' => 'Rendered with Mustache.php',
        'pageContent' => $allPages
    ));   
}

}

I have this master template called default.blade.php and a child page template called home.mustashe.

Problem is, I want to use the array containing all my page titles in the home.mustache template. how do add my array into the home.mustache template?

The code as it is now gives me following error: Array to string conversion

The Mustache Package i use is: Link to mustache package

Это было полезно?

Решение

That error means, quite literally, "You're trying to display an array as a string" ... which you haven't provided enough context do debug completely, but I'd guess means you're setting pageContent as an array of values, then calling {{ pageContent }} in a template.

Either convert your array to a string yourself:

implode(', ',  $allPages)

… or do something array-like with pageContent inside the template:

{{# pageContent }}<li>{{ . }}</li>{{/ pageContent }}

Другие советы

The docs on your Mustache package say arrays get handled as follows:

{{#posts}}
    {{> posts._post}}
{{/posts}}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top