kenjis / codeigniter-ss-twig

A Simple and Secure Twig integration for CodeIgniter 3.x and 4.x
MIT License
168 stars 46 forks source link

Render a Macro in a Template #23

Closed frost-byte closed 7 years ago

frost-byte commented 7 years ago

Add renderTemplateMacro to Twig wrapper Update README

I needed to update a view using an ajax call; this allows you to just run a macro from a template.

kenjis commented 7 years ago

In my understanding, macro is a function used in templates. So I don't want to merge this PR.

How about extending Twig library for your use case?

frost-byte commented 7 years ago

That's fine, I'm looking in how to use my fork via composer. I suppose that means that I'll need to watch your repo and merge in any releases you make.

kenjis commented 7 years ago

@frost-byte

  1. Create your Twig library which extends Twig class in this repository.
  2. Use your own Twig library.

For example: 1.

require_once __DIR__.'/Twig.php';

class My_twig extends Twig
{
    public function renderTemplateMacro($view, $macro, $params = [])
    {
        ...
    }
}

2.

$this->load->library('my_twig');
frost-byte commented 7 years ago

Thanks, that works.
Though, I can't access the private properties of the Twig class. I guess I'm just supposed to call getTwig in any class that extends yours? (Otherwise you'd have to make them protected properties.)

kenjis commented 7 years ago

@frost-byte I guess so. Why do you want to access the private properties?

frost-byte commented 7 years ago

That was meant as an aside. It's not necessary. But, it seemed strange for an extended class to call a getter of its parent. (I needed access to the twig property)