GithubHelp home page GithubHelp logo

wintersilence / kohana-template Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 1.0 68 KB

Template is extended KO7_View supports template engines

PHP 81.69% HTML 12.10% Smarty 6.21%
smarty twig fenom template-engine ko7 koseven kohana view template

kohana-template's Introduction

Template module for Koseven framework (Kohana fork)

Supported template engines:

Template

Template class extends View.

// Create view using default adapter
$view = Template::factory('news/list', ['news' => $posts]);
// Create view using Twig adapter
$view = Template::factory('news/list', ['news' => $posts], 'twig');
// Change adapter
$view->adapter('smarty');
// Get current adapter
$adapter = $view->adapter();
// Delete only local variables
$view->clear();
// Delete all variables
$view->clear(TRUE);
// Render content
$content = $view->render();
// Change template and adapter, render content and delete local variables
$content = $view->render($template, $adapter, TRUE);

Helper classes in template

Native

Helper method $this->template($template, $optional_data) render sub-template, uses adapter and variables of parent template.

<base href="<?=URL::base()?>">
<title><?=(isset($title) ? $title : '...')?></title>
<meta charset="<?=KO7::$charset?>">
<?=$this->template('menu/top')?>

Smarty

Calling helpers occurs without any problems.

<base href="{URL::base()}">
<title>{$title|default:'...'}</title>
<meta charset="{KO7::$charset}">

Twig

To use a helper is necessary to register them in config optiontemplate.twig.globals. Use a dot instead of a double colon for dividing the class and method in template.

<base href="{{ URL.base() }}">
<title>{{ title|default('...') }}</title>
<meta charset="{{ KO7.charset }}">

Fenom

Accepted only if config option template.fenom.options.disable_call is FALSE.

<base href="{$.call.URL::base()}">
<title>{$title ?: '...'}</title>
<meta charset="{$.call.KO7::charset}">

Controller_Layout

Controller_Layout extends Controller_Template. The controller uses nested templates:

  • $this->template main content
  • $this->layout content wrapper/theme $this->layout->bind('main_content', $this->template)

If $this->template filename not set, it's automatically generated by request (directory, controller and action).

class Controller_News extends Controller_Layout {
	// $this->layout = 'layout/bootstrap4';
	// $this->template = 'news/list';
	public function action_list()
	{
		// Adds banner to layout using  HMVC request
		$this->layout->sidebar = Request::factory('sidebar/news')->execute();
		// Adds news to template using ORM
		$this->template->news = ORM::factory('news')->find_all();
	}
}

kohana-template's People

Contributors

wintersilence avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

bosoy83

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.