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

pass by value in block node #44

Closed
ivix opened this issue Apr 16, 2010 · 3 comments
Closed

pass by value in block node #44

ivix opened this issue Apr 16, 2010 · 3 comments

Comments

@ivix
Copy link

ivix commented Apr 16, 2010

I think that in
Twig/lib/Twig/Node/Block.php lib/Twig/Node/Block.php on line 68

instead :
->write(sprintf("public function block_%s($context)\n", $this->name), "{\n")
must be:
->write(sprintf("public function block_%s(&$context)\n", $this->name), "{\n")

This need in case when need set value to context in child template and then parent read that value.

@fabpot
Copy link
Contributor

fabpot commented May 11, 2010

I think this is a bad idea, but can you give me a concrete example for that?

@ivix
Copy link
Author

ivix commented May 11, 2010

OK. Let we have index.phtml and index-overriden.phtml.

index.phtml:

Hello
{% block name %}
{% set name as 'John' %}
{% endblock %}

{{ name }}

index-overriden.phtml:

{% extends "index/index.phtml" %}
{% block name %}
{% set name as 'Overriden John' %}
{% endblock %}

if you open in browser index.phtml you will see only "Hello" word and in index-overriden.phtml you will see same result.

If change wig/lib/Twig/Node/Block.php as i show above;

Then content of index.phtml will be "Hello John" and content of index-overriden.phtml will be "Hello Overriden John ".

You can said that use some think like this in index.phtml:

Hello
{% block name %}
John
{% endblock %}

but when we have big template with not trivial or many overriden parts more easy override variables then put block in each place. Or for example when override one variable and then use in several places. I think this is useful ability.

If this bad idea can you said why, becouse i use this modification in my project.

@fabpot
Copy link
Contributor

fabpot commented May 12, 2010

Blocks are to be seen as methods. They are isolated. So, this is the expected behavoir. And I still don't see a real-world usage. The set tag is rarely useful in a template.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants