Skip to content

Commit 7a09b5e

Browse files
committed
BC break: rename render() to display()
Now render() returns rendered string
1 parent 1733856 commit 7a09b5e

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,20 @@ Load Twig library:
4444
$this->load->library('Twig');
4545
~~~
4646

47+
Render Twig template and output to browsers:
48+
49+
~~~php
50+
$this->twig->display('welcome', $data);
51+
~~~
52+
53+
Above code renders `views/welcome.twig`.
54+
55+
**Note:** I've changed the method name from `render()` to `display()`. Now `render()` method returns string only.
56+
4757
Render Twig template:
4858

4959
~~~php
50-
$this->twig->render('welcome', $data);
60+
$output = $this->twig->render('welcome', $data);
5161
~~~
5262

5363
Above code renders `views/welcome.twig`.
@@ -79,7 +89,7 @@ $ phpunit
7989

8090
## Other Implementations for CodeIgniter 3.0
8191

82-
* https://gitlab.com/david-sosa-valdes/ci-twig
92+
* https://gitlab.com/david-sosa-valdes/ci-attire
8393

8494
## Related Projects for CodeIgniter 3.0
8595

libraries/Twig.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,31 @@ public function setLoader($loader)
5555
$this->loader = $loader;
5656
}
5757

58+
/**
59+
* Renders Twig Template and Set Output
60+
*
61+
* @param string $view template filename without `.twig`
62+
* @param array $params
63+
*/
64+
public function display($view, $params = [])
65+
{
66+
$CI =& get_instance();
67+
$CI->output->set_output($this->render($view, $params));
68+
}
69+
70+
/**
71+
* Renders Twig Template and Retruns as String
72+
*
73+
* @param string $view template filename without `.twig`
74+
* @param array $params
75+
* @return string
76+
*/
5877
public function render($view, $params = [])
5978
{
6079
$this->createTwig();
6180

6281
$view = $view . '.twig';
63-
$CI =& get_instance();
64-
$CI->output->set_output($this->twig->render($view, $params));
82+
return $this->twig->render($view, $params);
6583
}
6684

6785
private function addCIFunctions()

0 commit comments

Comments
 (0)