Skip to content

Instantly share code, notes, and snippets.

@enov
Last active December 30, 2015 00:09
Show Gist options
  • Save enov/7747957 to your computer and use it in GitHub Desktop.
Save enov/7747957 to your computer and use it in GitHub Desktop.
How I use WinterSilence / kohana-meta-tags
<?php
// This works because we are rendering the content first
Meta::instance()->title('Home');
?>
Welcome to the Home Page!
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Page extends Controller {
public function action_page()
{
$page = $this->request->param('page');
if (Kohana::find_file('views', $page) === FALSE)
{
throw new HTTP_Exception_404('The requested page :page could not be found', array(
':page' => $page,
));
}
$content = View::factory($page)->render(); // be careful to render before template
$template = View::factory('template');
$template->set('content', $content);
$this->response->body($template);
}
}
<html>
<head>
<?= Meta::instance()->render()?>
</head>
<body>
<?=$content?>
</body>
</html>
@WinterSilence
Copy link

https://gist.github.com/enov/7747957#file-home-php-L4 here in violation of the concept of mvc - you set data in view

@enov
Copy link
Author

enov commented Dec 2, 2013

@WinterSilence,

I understand your concern. However, Welcome to the Home Page! is also some kind of data, right? Yet, it's hard-coded in view...

So why not have some pragmatism and add the title in the same file as content, since they are very related?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment