Sign up ×

I have written a training application with each page/slide of the training workbook as a seperate blade template file named as "page1.blade.php", "page2.blade.php" and so on. Each of these files has content of the kind:


{{-- Page title --}}
    Page Title

{{-- Page content --}}
    <div class="pageContentContainer">
        <h2>Page Title</h2>

This works really well when being viewed page by page within the browser. However I also wish to automatically compile all pages into a PDF document. This is being done via dompdf which works amazingly well when I pass each pages html to it manually. However I wish to condense the @section('pageContent') section of each page into one large section which extends a different layout for passing to dompdf.

Given the above context my question is this: Is there a method in Laravel's blade parser which would allow me to pass it a blade file and just get the rendered html from a particular section? The below pseudo-code demonstrates what I would like to be able to do.

$pages = array(...); // content of the directory
foreach ($pages as $page)
    $renderedPage = Blade::render($page);
    $title = $renderedPage->title;
    $pageContent = $renderedPage->pageContent;
share|improve this question

1 Answer 1

up vote 2 down vote accepted

Instead of doing the normal return of view

return View::make('page');

You can instead store the view in a string

$view = View::make('page');

So then you can do your code something like this (not tested - but you get the idea):

foreach ($pages as $page)
    $renderedPage[] = view::make($page);
share|improve this answer
This was useful, I then had to break down the string line by line and just grab the lines between the @section('title') and @parent. –  carbontwelve Aug 30 '13 at 8:27

Your Answer


