Skip to content

Instantly share code, notes, and snippets.

@chucktrukk
Created December 8, 2011 22:30
Show Gist options
  • Save chucktrukk/1448976 to your computer and use it in GitHub Desktop.
Save chucktrukk/1448976 to your computer and use it in GitHub Desktop.
quick method to send class to twig
<?php
class AnyClassUsa {
public function render($template)
{
$twig = $this->twig;
foreach(get_object_vars($this) as $property => $value) {
$params[$property] = $value;
}
$params['this'] = $this;
try {
$template = $twig->loadTemplate($template);
} catch(Exception $e) {
return "Unable to find template '{$template}'";
return $e->getMessage();
}
try {
return $template->render($params);
} catch(Exception $e) {
return $e->getMessage();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment