Commit Graph

1667 Commits

Author SHA1 Message Date
Fabien Potencier bcf850da50 fixed a stupid test 2012-10-30 18:12:52 +01:00
Fabien Potencier 1be2495906 fixed broken test 2012-10-30 17:46:49 +01:00
Fabien Potencier 8c5853e3b1 fixed bitwise operator precedences (closes #866) 2012-10-30 17:40:56 +01:00
Fabien Potencier bf3802bc6e merged branch fabpot/template_from_string (PR #874)
This PR was merged into the master branch.

Commits
-------

4599188 added the template_from_string function

Discussion
----------

added the template_from_string function

One of the most often asked question is how someone can evaluate a template string from a template.

The template_from_string function solves this problem (more in the included docs).

I have two questions before merging this:

 * What about the name? I find it quite long but also readable (`{% include template_from_string(template) %}`).

 * Does it belongs to Twig core?

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

by boutell at 2012-10-28T16:45:08Z

Interesting. What are the use cases? Would it cache in some way, the md5 of the string maybe, to avoid having this be a major performance hit on every use?

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

by gcoguiec at 2012-10-28T16:46:04Z

And what about include_from_string ?

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

by lsmith77 at 2012-10-28T16:46:35Z

Heh, was just going to ask the same thing, would a use case be loading a twig snippet from a database? something like https://github.com/symfony-cmf/ContentBundle/issues/8 ..

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

by stof at 2012-10-28T16:48:09Z

@gcoguiec It is not including anything but creating a Twig_Template instance. ``{% extends include_from_string(foo) %}`` would be very ugly.

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

by gruzilla at 2012-10-28T16:48:37Z

i'd say yes.
im not like the core must can do everything. but besides that, what are the reasons against it?
i can already think of some usecases: user defined dynamic templates, ...

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

by alexandresalome at 2012-10-28T16:49:34Z

IMHO it's a mistake to put it in Twig. People won't get how to use it. My reasons are also regarding cache: will the template be regenerated on each call?

Looks magic

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

by stof at 2012-10-28T16:50:06Z

@fabpot I'm not really sure this should be in the core.
But FYI, there is a [PR on your Twig-extensions repository](https://github.com/fabpot/Twig-extensions/pull/68) adding an ``eval`` function with the same goal (but an incomplete implementation)

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

by fabpot at 2012-10-28T16:51:00Z

The template is loaded like any other ones, so it is using the cache if you have configured it. No magic included!

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

by fabpot at 2012-10-28T16:52:44Z

@lsmith77 yes, that's the main use case.

You can also have a look at this thread on the mailing-list: https://groups.google.com/group/twig-devs/browse_thread/thread/a8b7bbae31cade18

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

by fabpot at 2012-10-28T16:54:28Z

I forgot to say that we can also move this function into its own extension, so that enabling it would have to come from a conscious choice from the developer (like the debug function in the debug extension).

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

by lsmith77 at 2012-10-28T16:55:32Z

OK great. Looks like something the CMF will need then. But it would also work for us if its part of the twig extension repo. we could of course also just drop the code into https://github.com/symfony-cmf/CoreBundle/blob/master/Twig/TwigExtension.php

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

by fabpot at 2012-10-28T16:56:59Z

I have proposed it for inclusion in Twig core (but not necessarily in the core extension) as it seems to be something many developers want to do in their code (mainly people writing a CMS in top of Twig).

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

by dlsniper at 2012-10-28T17:05:45Z

Hi

- why not name it `template_string` or `string_template`? Then it would read like: ` {% include template_string(template) %} ` or ` {% include string_template(template) %} `

- imo this shouldn't be in the core but rather in the extensions part of Twig as you just extend existing Twig functionality :)

Cheers.

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

by fabpot at 2012-10-28T17:37:12Z

I've moved the function to a new extension that should be enabled explicitely.

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

by EvanK at 2012-10-28T18:05:57Z

I would love to see this as a built-in feature to Twig, as my coworkers & I have had to implement a workaround for something similar.

(Our workaround involved writing said string to a file named after an md5 of the string's content, and then calling render() on said file, all within the php userspace. It was less than elegant, but functional.)

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

by Crell at 2012-10-28T19:11:34Z

This would lend itself to some of the wacky stuff Drupal has been discussing, too.  +1 on the feature.  No opinion on the name.

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

by jorgelbg at 2012-10-28T20:45:37Z

+1 for built-in support i think this is something Twig should do out of the box, regarding the name I guess that I'll vote for this name ```{% include from_string(template) %}``` The only thing that you can include is a template righ? So why put this explicitly in the function's name?

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

by pylebecq at 2012-10-29T09:53:05Z

+1 for me. And for the name, it seems I'm the only one but I would have vote for `eval` 😈

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

by sstok at 2012-10-29T10:14:25Z

eval is bad name as can be confused with eval() in PHP, aka that what is passed is treated as PHP (similar to embeded PHP in Smarty). Please don't..

+1 for as it is now.

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

by drak at 2012-10-29T17:25:24Z

Love it +1

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

by acasademont at 2012-10-30T12:02:40Z

Very useful feature! +1

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

by acasademont at 2012-10-30T12:20:46Z

For clarification, now if you wanted to make dynamic include or dynamic inheritance like this ```{% extends some_var %}``` you had to supply a valid Twig_Template object. Now with this function you can supply a simple string that will be evaluated and transformed into a Twig_Template object. So this PR is not inventing dynamic inheritance but providing a helper to make it easier. Am I right?

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

by stof at 2012-10-30T12:45:08Z

@acasademont no. It is provinding a way to evaluate a string stored somewhere (in a database for instance) as a template. It is not about making dynamic inheritance easier.
If your template can be loaded by your loader (for instance a file when using the Twig_Loader_Filesystem), you can use the template name in your variable for the dynamic inheritance. You are not required to build the Twig_Template instance yourself

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

by fabpot at 2012-10-30T12:53:02Z

When you have `{% extends some_var %}`, `some_var` must be the template name. Using `{% extends template_from_string(some_var) %}` means that `some_var` contains the parent template code.

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

by acasademont at 2012-10-30T13:15:37Z

Perfectly understood, thanks!
2012-10-30 16:42:59 +01:00
Fabien Potencier 1881045806 added a note about double-escaping when using a variable for the strategy (closes #868) 2012-10-30 10:27:26 +01:00
Fabien Potencier e3830c70aa fixed default timezone usage for the date function (refactor of the previous merge) 2012-10-30 09:53:04 +01:00
Fabien Potencier ea42eb4dd1 merged branch vitman/patch-1 (PR #871)
This PR was squashed before being merged into the master branch (closes #871).

Commits
-------

b89163d Update lib/Twig/Extension/Core.php

Discussion
----------

Update lib/Twig/Extension/Core.php

Added support for setted default timezone for twig date functions.

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

by henrikbjorn at 2012-10-26T07:19:02Z

This have the same problem as the other PR you created. See php.net/datetime for reference.
2012-10-30 09:40:23 +01:00
vitman b89163df0c Update lib/Twig/Extension/Core.php 2012-10-30 09:40:22 +01:00
Fabien Potencier 459918827b added the template_from_string function 2012-10-29 11:42:14 +01:00
Fabien Potencier 0505c2fefd added two new recipes 2012-10-28 15:30:18 +01:00
Fabien Potencier d59642c949 added missing documentation about Twig_Loader_Chain 2012-10-28 15:19:48 +01:00
Fabien Potencier 42df784d04 fixed phpdoc 2012-10-28 14:36:27 +01:00
Fabien Potencier 8dbe803b29 merged branch jeremymarc/master (PR #873)
This PR was merged into the master branch.

Commits
-------

c5d351d cast $name to string ($name can be an object implementing __toString function)

Discussion
----------

Cast $name to string in Loader/Chain.php and Loader/FileSystem.php

related to #603
2012-10-27 08:23:19 +02:00
Jeremy Marc c5d351dcd2 cast $name to string ($name can be an object implementing __toString function) 2012-10-26 15:30:04 -07:00
Fabien Potencier 61393dc9fb merged branch fabpot/faster-exceptions (PR #864)
This PR was merged into the master branch.

Commits
-------

2506be1 optimized the way Twig exceptions are managed

Discussion
----------

Optimized the way Twig exceptions are managed

As guessing the template name and the line number of where an error occurred is quite expensive, this is now avoided as much as possible.

~~As a side-effect, it also fixes 822 (@hason can you confirm?).~~
2012-10-20 14:53:18 +02:00
Fabien Potencier 2506be1794 optimized the way Twig exceptions are managed
As guessing the template name and the line number of where an error
occurred is quite expensive, this is now avoided as much as possible.
2012-10-19 14:45:58 +02:00
Fabien Potencier 244eaf53b3 updated the docs for the new Twig_ExistsLoaderInterface interface 2012-10-19 14:36:16 +02:00
Fabien Potencier 09ba90919e renamed Twig_ExtendedLoaderInterface to Twig_ExistsLoaderInterface 2012-10-19 14:34:08 +02:00
Fabien Potencier ed0554610a merged branch dlsniper/loader-exception-improvement (PR #841)
This PR was squashed before being merged into the master branch (closes #841).

Commits
-------

08ecb0e Improvements for loader speeds

Discussion
----------

Improvements for loader speeds

This is something started from #822 .

It attempts to improve the speed of the chain loader and rest of the standard loaders by adding a cache level and a ```hasSource()``` method for them in order gain speed.

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

by dlsniper at 2012-09-27T14:56:24Z

Thanks for the feedback, I'll do the changes tonight or during the coming weekend.

As for the utility of the ```::setExtendedErrorHandling()``` function, this saves me about 25% to 40% on the benchkmark Fabien presented in the original ticket.

Thanks!

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

by dlsniper at 2012-09-29T11:34:59Z

I've added some caching for the Chain Loader but it's still a WIP. I'll work more on this in the coming hours.

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

by dlsniper at 2012-09-29T23:10:10Z

I'm getting better values right now that I had before, standing on:
```
0.09
0.07 ... x 1
0.07 ... x 1
```
I've also noticed that if I run the tests from the browser then I'll have an overall slowdown of about 0.10 which I'm not sure from where it comes from. Any pointers before me digging a bit more into Twigs internals.

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

by dlsniper at 2012-10-03T21:31:15Z

@fabpot what's your opinion about this PR?

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

by dlsniper at 2012-10-14T18:26:13Z

@Tobion and @fabpot done and done :)

I'm not sure why the tests are failing on PHP 5.4 as I don't have it installed anywhere.
2012-10-19 14:27:33 +02:00
Florin Patan 08ecb0e1c4 Improvements for loader speeds 2012-10-19 14:27:32 +02:00
Fabien Potencier af1bfe9516 bumped version to 1.11.0-DEV 2012-10-19 12:48:39 +02:00
Fabien Potencier 79671473d2 prepared the 1.10.3 release v1.10.3 2012-10-19 12:45:49 +02:00
Fabien Potencier 3031fe6b95 changed Node instances line numbers from 0 to 1 in unit tests to better reflect what really happens when using Twig 2012-10-19 08:48:03 +02:00
Fabien Potencier bc64a7f7fa updated CHANGELOG 2012-10-18 14:01:42 +02:00
Fabien Potencier a4490975d3 reverted BC break 2012-10-18 13:59:31 +02:00
Fabien Potencier 191c9220c3 moved some logic from the sandbox node visitor to the sandbox node 2012-10-18 13:55:03 +02:00
Fabien Potencier 580508eda4 fixed wrong exception class in the filesystem loader 2012-10-18 08:36:07 +02:00
Fabien Potencier 650295f592 fixed wrong template location in error messages (closes #803) 2012-10-18 08:21:41 +02:00
Fabien Potencier 3506cfad1d added missing version info in the docs for the split filter 2012-10-18 08:21:41 +02:00
Fabien Potencier bac6bc7851 fixed previous merge 2012-10-16 14:39:58 +02:00
Fabien Potencier a2981f7d8c merged branch innsand/split-filter_fix (PR #811)
This PR was merged into the master branch.

Commits
-------

d5df200 * bug fixes. * str_split on empty delimeter. * tests and documentation updated.
e3c201a Added "split" filter aka explode.

Discussion
----------

Split filter fix

Modification of request #621:
str_split, bug fixes

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

by senz at 2012-08-21T05:56:51Z

@fabpot this is squashed and fixed (hopefully) #621
2012-10-16 14:33:18 +02:00
Fabien Potencier 78669a66d0 fixed import doc 2012-10-16 07:57:52 +02:00
Fabien Potencier 4db861aedb bumped version to 1.10.3-DEV 2012-10-15 10:26:17 +02:00
Fabien Potencier 5d1c9e1370 prepared the 1.10.2 release v1.10.2 2012-10-15 10:23:34 +02:00
Fabien Potencier be3a5a6421 fixed macro calls on PHP 5.4 2012-10-15 10:22:32 +02:00
Fabien Potencier f48f23a34d bumped version to 1.10.2-DEV 2012-10-15 09:38:17 +02:00
Fabien Potencier f88881cece prepared the 1.10.1 release v1.10.1 2012-10-15 09:35:01 +02:00
Fabien Potencier a6473b7cfd updated macro documentation to warn about a hack that won't work anymore in Twig 2.x 2012-10-15 09:15:27 +02:00
Fabien Potencier 82334f876f merged branch Adel-E/update-api-docs (PR #858)
This PR was merged into the master branch.

Commits
-------

bee4cd1 Update doc to correspond to the following: http://twig.sensiolabs.org/documentation http://twig.sensiolabs.org/doc/filters/escape.html

Discussion
----------

Update api docs

Update doc to correspond to the following:
http://twig.sensiolabs.org/documentation
http://twig.sensiolabs.org/doc/filters/escape.html
2012-10-13 21:01:24 +02:00
eadel bee4cd12db Update doc to correspond to the following:
http://twig.sensiolabs.org/documentation
http://twig.sensiolabs.org/doc/filters/escape.html
2012-10-12 21:51:42 +00:00
Fabien Potencier e1e9802c56 fixed tests where macros were not used properly 2012-10-12 16:53:20 +02:00
Fabien Potencier 9728a5de40 refactored previous commit to avoid collission between symbols of different types 2012-10-12 16:47:13 +02:00
Fabien Potencier a4e10c14ed optimized macros when imported via the "import" tag
This commit unifies the way macros are called independently of how they
were included (via the from or import tag -- see e81c932).
2012-10-12 16:09:40 +02:00
Fabien Potencier 347bc81d6e merged branch pierrejoye/master (PR #855)
This PR was merged into the master branch.

Commits
-------

d398e55 - drop tsrm fetch, not necessary as it is passed as argument already

Discussion
----------

drop unnecessary tsrmls_fetch
2012-10-08 15:20:00 +02:00
Pierre Joye d398e557e3 - drop tsrm fetch, not necessary as it is passed as argument already 2012-10-08 15:15:38 +02:00
Fabien Potencier 5d7baaf767 refactored some unit tests 2012-10-06 09:21:32 +02:00
Fabien Potencier 7dd2f17646 updated CHANGELOG 2012-10-05 17:09:05 +02:00
Fabien Potencier 8b63fbe72f fixed unit tests when XDebug is enabled 2012-10-05 17:04:55 +02:00
Fabien Potencier 515f34abc3 merged branch weltling/master (PR #854)
This PR was merged into the master branch.

Commits
-------

b013ede fix windows build

Discussion
----------

Trivial fix for windows build
2012-10-04 19:41:45 +02:00
Anatoliy Belsky b013ede1fa fix windows build 2012-10-04 18:50:52 +02:00