Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return data for use in extensions #66

Merged
merged 2 commits into from
Dec 27, 2016
Merged

Return data for use in extensions #66

merged 2 commits into from
Dec 27, 2016

Conversation

electricjones
Copy link
Contributor

In response to #60 this pull request gives access to template data for extensions. In effect, calling $template->data() with no arguments will return the data array. I added a test for this. I am doing another pull request for documentation.

Now you can do what was described to badpenguin. I've check this. It works wonderfully.

<?php

use League\Plates\Engine;
use League\Plates\Extension\ExtensionInterface;

class MyExtension implements ExtensionInterface
{
    public $template;

    public function register(Engine $engine)
    {
        $engine->registerFunction('default', [$this, 'extension_default']);
    }

    function extension_default($var, $def = '')
    {
        $data = $this->template->data();

        if (isset($data[$var])) {
            return $data[$var];
        }

        return $def;
    }
}

And in the template

<html lang="<?=$this->default('page_lang', 'en')?>">

If you've already implemented this, or if you wanted to do it a different way, no biggie. Just though I'd pitch it.

@reinink
Copy link
Contributor

reinink commented Feb 19, 2015

Hey @chrismichaels84, thanks for all the work you've put into this library the last few days! I'm having a REALLY busy week, and while I want to dig through all your pull requests right now, I probably won't have a chance until next week. Please be patient with me. :)

@electricjones
Copy link
Contributor Author

Take your time man. I'm just wantin' to help out.

@eko3alpha
Copy link

I was looking for a solution to this very issue and noticed in your example you're missing a closing ( ' ) after page_lang

<html lang="<?=$this->default('page_lang, 'en')?>">

should be

<html lang="<?=$this->default('page_lang', 'en')?>">

@electricjones
Copy link
Contributor Author

ah...quotes and semicolons. The bane of my existence. Thanks for the catch.

Any word on these Pull Requests?

@reinink
Copy link
Contributor

reinink commented Apr 20, 2015

@chrismichaels84 Soon. Very sorry for the delay. See this and maybe this.

@electricjones
Copy link
Contributor Author

Lol, I hear you man. No problem. I'm running what I need off my fork
anyway. Good luck.

On Mon, Apr 20, 2015 at 2:24 PM, Jonathan Reinink notifications@github.com
wrote:

@chrismichaels84 https://github.com/chrismichaels84 Soon. Very sorry
for the delay. See this
https://twitter.com/reinink/status/590132420558639104 and maybe this
https://twitter.com/reinink/status/590132439986610176.


Reply to this email directly or view it on GitHub
#66 (comment).

@ragboyjr
Copy link
Contributor

👍

@ragboyjr ragboyjr mentioned this pull request Dec 26, 2016
@ragboyjr
Copy link
Contributor

@chrismichaels84 Are you around to support this PR? It looks like your original plates repo is gone.

@reinink reinink merged commit 96128c2 into thephpleague:master Dec 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants