I don't see many tutorials on templates in FuelPHP online. The section in the official documentation doesn't really explain anything.

Are there any examples or tutorials out there that someone can recommend?

有帮助吗?

解决方案

There isn't really such a thing as a template in FuelPHP.

There is a template controller, which will allow you to set a view as a 'page template', and will automatically render it when your controller action is finished.

So the template in that controller is a normal view. Passing sections to it is nothing more then passing variables to it, that may contain another View object (for example a header or a footer view). http://fuelphp.com/docs/general/views.html has an example, under 'nested views'.

If you want a more flexible system, you should have a look at the Theme class, which works with themes (multiple), templates, partials, theme fallback, central view folders, etc.

其他提示

For using fonctionalities of Fuelphp Controller_Template, create a default view called template.php with the basics elements:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="utf-8">
    <title>Website<?php echo isset($title) ? ' - '.$title : ''; ?></title>
    <?php echo Asset::css('style.css'); ?>
    <?php echo Asset::js('global.js'); ?>
</head>
<body>
    <div id="header">
        <!-- Some code -->
    </div>
    <div class="container">
        <?php echo isset($content) ? $content : ''; ?>
        <hr/>
        <footer>
            <!-- Some code -->
        </footer>
    </div>
</body>
</html>

Then in the Controller of your page (ex: Controller_Home) extends the Controller_Template and put those variable in a function before():

class Controller_Home extends \Fuel\Core\Controller_Template
{
    public function before()
    {
        parent::before();
        $this->template->menu = 'home';
        $this->template->title = 'Home';
    }
}

Then when you want to call a page in this Controller (ex: index.php) try this:

public function action_index()
{
    $this->template->content = View::forge('home/index');
}

It will display the template and your page (view) index.php.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top