Commit Graph

803 Commits

Author SHA1 Message Date
Fabien Potencier 26d8aff746 refactored code 2011-08-06 10:44:55 +02:00
Fabien Potencier 440d13753a added the possibility to test for exceptions in integration tests 2011-08-06 09:49:38 +02:00
Fabien Potencier 801f3e638c removed the possibility to use the extends tag from a block (as it is semantically incorrect and it probably does not work as you expect it to in this case) 2011-08-06 09:16:10 +02:00
Fabien Potencier c201137f21 moved Template::getParent() logic to the base class 2011-08-06 09:09:18 +02:00
Fabien Potencier 46eccb9ab5 added documentation for previous merge 2011-08-06 08:44:04 +02:00
Fabien Potencier d306dabea3 fixed unit tests for previous merge 2011-08-06 08:35:41 +02:00
Fabien Potencier 1202b5fbe7 merged branch kotas/master (PR #362)
Commits
-------

f5b9df9 added `if` modifier support to for loop like {% for k in v if k is odd %}

Discussion
----------

[1.2] added `if` modifier support to for loop

Hi.

I'm one of Twig users who love it so much. :)

I've made a patch for adding `if` modifier support to `for` loop in Twig.

Example:
<pre>
{% for n in range(0, 5) if n is odd %}
  {{ n }}
{% endfor %}
</pre>

Output:
<pre>
1
3
5
</pre>

This idea comes from Python's list comprehensions. (like `[n for n in range(0,6) if n % 2 == 1]`)

Here is another example.

Before:
<pre>
{% set no_items = true %}
{% for item in items %}
  {% if item.available %}
    {% set no_items = false %}
    {{ item.name }}
  {% endif %}
{% endfor %}
{% if no_items %}
  No items available.
{% endif %}
</pre>

After:
<pre>
{% for item in items if item.available %}
  {{ item.name }}
{% else %}
  No items available.
{% endfor %}
</pre>

I hope you like it. But If not, just ignore this request. :)

Thanks.

---------------------------------------------------------------------------

by fabpot at 2011/06/24 01:33:33 -0700

I like it! I will schedule it for inclusion in Twig 1.2. Thanks.

---------------------------------------------------------------------------

by hhamon at 2011/06/26 16:43:26 -0700

+1

---------------------------------------------------------------------------

by nikic at 2011/06/27 00:42:14 -0700

I think the idea per se is interesting. But I just checked all Twig templates in my whole codebase and couldn't find any use for it. What was your practical use for this feature @kotas?

---------------------------------------------------------------------------

by kotas at 2011/06/27 01:52:48 -0700

@nikic My practical use is shown as the second example in the body of this pull request.

Sometimes you need to "filter" an array by seeing its element's property like "item.available" or by some condition like "item.price >= 500".

To do this, in the current version of Twig, you have to write "for" and "if" as nested scopes. And if you want to write {% else %} of the "for" loop, you have to make a temporary variable to see if all elements are skipped.

I think this feature is not essential, but makes templates clean.

---------------------------------------------------------------------------

by nikic at 2011/06/27 06:23:24 -0700

The thing about `else` seems plausible. +1

---------------------------------------------------------------------------

by chucktrukk at 2011/08/02 17:39:16 -0700

Also +1. that makes some very clean template code.
2011-08-06 08:34:15 +02:00
Fabien Potencier e6dde1d6df added GtkSourceView support in doc 2011-08-06 08:16:57 +02:00
Fabien Potencier d55ca98bc3 merged branch igorw/recipes-highlight (PR #405)
Commits
-------

0580f19 fix highlighting of snippet in recipes doc

Discussion
----------

fix highlighting of snippet in recipes doc
2011-08-04 10:29:19 +02:00
Igor Wiedler 0580f192ca fix highlighting of snippet in recipes doc 2011-07-31 02:25:43 +02:00
Fabien Potencier f918219cf9 bumped version to 1.2.0-DEV 2011-07-30 10:10:16 +02:00
Fabien Potencier 396435ecd0 prepared 1.1.2 released v1.1.2 2011-07-30 09:53:59 +02:00
Fabien Potencier 9b73026e91 fixed Parser bug when a child node is null 2011-07-28 14:32:45 +02:00
Fabien Potencier ef485402e0 fixed Parser bug 2011-07-28 14:32:07 +02:00
Fabien Potencier c7be5242c4 fixed unit test, updated CHANGELOG 2011-07-27 14:25:09 +02:00
Fabien Potencier 945579a8f6 merged branch JEDIBC/master (PR #401)
Commits
-------

755ea99 Correction of a BC break with json_encode and PHP 5.2.x

Discussion
----------

BC break with json_encode and php 5.2.x

Hi,

json_encode on php 5.2.x doesn't take the $options parameter wich result in a warning and the function return nothing.

Cheers.
2011-07-27 14:23:49 +02:00
JEDIBC 755ea99bd4 Correction of a BC break with json_encode and PHP 5.2.x 2011-07-27 12:25:24 +02:00
Fabien Potencier 26757ab327 simplified code for previous merge/commits 2011-07-27 11:23:08 +02:00
Fabien Potencier 21c96d1ef4 changed previous commit to preserve better BC 2011-07-27 10:12:28 +02:00
Fabien Potencier 56e2ca75fa fixed CS on template output 2011-07-27 09:44:25 +02:00
Fabien Potencier b4e9c0f6d8 updated CHANGELOG 2011-07-27 09:36:26 +02:00
Fabien Potencier 1f233ce06b fixed previous merge 2011-07-27 09:34:28 +02:00
Fabien Potencier a6726c7ddd merged branch hason/optimizer (PR #399)
Commits
-------

3c5c512 fixed optimization for rendering blocks with variable name

Discussion
----------

Fixed bug in optimization
2011-07-27 09:33:41 +02:00
Martin Hason 3c5c51260e fixed optimization for rendering blocks with variable name 2011-07-27 08:19:59 +02:00
Fabien Potencier d67832ea5d updated CHANGELOG 2011-07-26 17:36:37 +02:00
Fabien Potencier 74d2f76c23 fixed inherited templates when an empty body 2011-07-26 17:32:54 +02:00
Fabien Potencier 6e97162de4 merged branch netzhuffle/master (PR #396)
Commits
-------

7b154d6 Switched a tab to four spaces
29d3cb2 Added testcase for #395
4fc7a8d Merge remote-tracking branch 'upstream/master'
c890cf2 Fixed existing tests
9822ac4 Changed Module.php to pass existing tests
fab8c72 fixed issue #395

Discussion
----------

Fix for issue #395

Fix for #395
I hope you can use it.

---------------------------------------------------------------------------

by fabpot at 2011/07/25 00:07:50 -0700

Can you add some unit tests?

---------------------------------------------------------------------------

by netzhuffle at 2011/07/25 13:57:55 -0700

Here you are.
2011-07-26 17:30:32 +02:00
Fabien Potencier 3ae35949ac removed comment 2011-07-26 08:07:02 +02:00
Fabien Potencier 7f5390a6a7 fixed compilation of templates when the body of a child template is not empty 2011-07-26 08:02:51 +02:00
Jannis Grimm 7b154d66fd Switched a tab to four spaces 2011-07-25 23:10:29 +02:00
Jannis Grimm 29d3cb2b91 Added testcase for #395 2011-07-25 22:55:53 +02:00
Jannis Grimm 4fc7a8d21b Merge remote-tracking branch 'upstream/master' 2011-07-25 22:32:17 +02:00
Jannis Grimm c890cf2b64 Fixed existing tests 2011-07-25 22:29:47 +02:00
Jannis Grimm 9822ac491e Changed Module.php to pass existing tests 2011-07-25 22:12:48 +02:00
Fabien Potencier 53eca627a6 simplified CHANGELOG 2011-07-25 18:46:01 +02:00
Fabien Potencier b42d8f3e29 updated CHANGELOG 2011-07-25 18:14:12 +02:00
Fabien Potencier ea83972869 fixed output when a macro throws an exception 2011-07-25 18:12:59 +02:00
Fabien Potencier 42e4105595 fixed PHPDocs for the Token parsers 2011-07-25 18:05:31 +02:00
Fabien Potencier e3bd4bdcdd fixed PHPDocs for the Core extension 2011-07-25 17:56:29 +02:00
Fabien Potencier e08de0d7cf merged branch pulse00/master (PR #389)
Commits
-------

351910b added twig comments
2b7e8d9 added phpDocs for TokenParsers, filters and tests

Discussion
----------

PHPDocs updated

fixed copy/paste errors and added docs to Sandbox and Use tags
2011-07-25 15:52:46 +02:00
Fabien Potencier 6783d5812b fixed a parsing problem when a large chunk of text is enclosed in a comment tag 2011-07-25 15:51:24 +02:00
Jannis Grimm fab8c72d08 fixed issue #395 2011-07-24 22:55:34 +02:00
Fabien Potencier e44ea9b0d4 added filename when throwing an exception when we know it 2011-07-19 15:27:34 +02:00
Robert Gruendler 351910bf21 added twig comments 2011-07-18 14:35:57 +02:00
Robert Gruendler 2b7e8d9da9 added phpDocs for TokenParsers, filters and tests 2011-07-18 13:32:46 +02:00
Fabien Potencier 94ac20f155 prepared 1.1.1 release v1.1.1 2011-07-17 15:53:10 +02:00
Fabien Potencier d95aeed935 made a small optimization on Core functions 2011-07-16 21:08:20 +02:00
Fabien Potencier a27175b76a added an optimization to the Optimizer 2011-07-16 20:38:00 +02:00
Fabien Potencier 2527c6564b updated CHANGELOG 2011-07-12 10:04:49 +02:00
Fabien Potencier 2f3dd84890 fixed CS 2011-07-12 09:50:37 +02:00