Commit Graph

500 Commits

Author SHA1 Message Date
Grégoire Paris d52e15bd36 remove tautology 2012-09-29 19:02:16 +03:00
Fabien Potencier 2f7b43be74 fixed a doc anchor 2012-09-29 18:01:41 +02:00
Fabien Potencier 66a8c0b89e tweaked docs 2012-09-18 11:37:33 +02:00
Drak 36372c61d3 Made node tests reusable 2012-09-18 10:13:12 +01:00
Fabien Potencier c38e06ff41 added missing information in the doc 2012-09-16 16:38:44 +02:00
Fabien Potencier c420462b5b merged branch fabpot/named-paths (PR #772)
Commits
-------

7e5acd1 fixed some possible warnings
f0d0d6d fixed typo
b7076fe added Twig_Loader_Filesystem::getNamespaces()
8f7ccd1 moved an exception
9426072 tweaked documentation
b9afa84 renamed the default filesystem namespace to __main__
c34541d changed notation of namespaced templates to @namespace/template_path
0eb4d01 added namespaced templates support in Twig_Loader_Filesystem
c24ea1b added Twig_Loader_Filesystem::prependPath()

Discussion
----------

added namespaced templates support in Twig_Loader_Filesystem

Everything is explained in the updated documentation.

Basically, it gives more flexibility when it comes to manage many templates that are not necessarily related (think frontent vs backend for instance, or templates from different Symfony bundles, ...). It is useful if, for each namespace, you need to look for templates in different directories. This implementation would probably be enough to replace the current Symfony bundle template paths, with more flexibility and less restrictions.

Feedback is more than welcome. One thing I'm not sure about is the `#` separator between the namespace and the template path. Is it the best choice? We need a character that is not used in filesystem paths, so good candidates are: `@`, `!`, `%`, `$`, `*`, `;`, `?`.

Some immediate benefits: give the same template flexibility that we have in Symfony to other frameworks using Twig like Silex. Another benefit would be the ability to share template between Symfony and other frameworks like Twig (more on a proof of concept later).

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

by alessandro1997 at 2012-07-14T16:25:42Z

This is very nice, and I think # is a great choice for the separator character. We could also use @.

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

by jjbohn at 2012-07-14T16:25:59Z

👍 for #

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

by Symfomany at 2012-07-14T16:27:45Z

Pipe character isn't candidate?

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

by inspiran at 2012-07-14T16:32:52Z

I remember from the wetter.com talk at sf live that they actually implemented a similar functionality: allow twig templates to be defined different from the default path.   So they had something like:

{% extends "cms://Home/weather/..."  ... %}
If we could make the "cms" part a configurable setting then one could use it to point to a custom folder or even to a content provider (symfony cmf?)

Maybe that would be another approach?

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

by fabpot at 2012-07-14T16:33:21Z

The other syntax possibility is something more like we have in Symfony: `@namespace/template_path`.

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

by fabpot at 2012-07-14T16:34:37Z

@inspiran: that's another possibility: use the PHP stream notation.

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

by mvrhov at 2012-07-14T16:36:18Z

I'd also prefer uri/php streams syntax...

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

by Tobion at 2012-07-14T16:41:16Z

On Windows I can create a file with `#` in it. How does it distinguish that? I don't think we will find a single seperation character that works on all file systems, do we? And `@` (e.g. namespace@file) would be semantically strange (unless you read it from right-to-left).
So I'd also prefer uri/php stream syntax.

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

by Symfomany at 2012-07-14T16:43:17Z

@fabpot  Pointer Syntax? or greater than character?

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

by markstory at 2012-07-14T16:43:48Z

I'm in favour of the `foo://` style syntax.  It is similar to other parts of PHP, and avoids overlap with filesystem characters, and doesn't introduce new unique syntax.

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

by stof at 2012-07-14T16:44:25Z

@fabpot ``@namespace/template_path`` would make it confusing in Symfony. Because locating a resource with the kernel would use ``@AcmeDemoBundle/Resources/views/layout.html.twig`` whereas Twig would find the same file as ```@AcmeDemoBundle/layout.html.twig``.

And none of ``#``, ``@``, ``!``, ``%``, ``$`` or ``;`` is forbidden in filenames on Windows.

So I think the URI/stream notation is fine

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

by maryo at 2012-07-14T16:46:44Z

On Windows @!%$; are valid. Invalid characters are \/:*?"<>|

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

by maryo at 2012-07-14T16:47:55Z

Is > allowed on Linux?

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

by jschreuder at 2012-07-14T16:49:17Z

Some thoughts from a non-Symfony user:

* Not sure about the `#`, on the one hand it is used as the comment character on the other hand I'm also familiar with it as a membership operator (which supports its usage)
* The streams/PHP syntax: I don't really like this, the syntax signifies some type of protocol to be used. Even stretched to the limits of its definition you wouldn't be able to define different namespaces as different protocols (same protocol, different location).
* `@namespace/file/path` - kind of like this one, the `@` signifies that it is followed by a special symbol (being the namespace name) and other than that a normal path.
* Another option we've used in Fuel is the double colon `::` as in `namespace::file/path` (like the `#` it signifies membership, but doesn't have another significance in Twig)

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

by gunnarlium at 2012-07-14T17:10:15Z

Does it matter what symbols are valid in filenames? Won't the separator just be used for exploding the string into namespace and path, and thus never be used to directly access a file?

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

by alessandro1997 at 2012-07-14T17:15:27Z

As @gunnarlium said, what's the problem with filenames?

```php
$path = 'namespace#new#page.html';
$parts = explode('#', $path, 2);
list($namespace, $filename) = $parts;

// "namespace and "new#page.html"
var_dump($namespace, $filename);
```

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

by stof at 2012-07-14T17:16:19Z

@gunnarlium the issue is that if you use this symbols in the filename of your template without namespace, Twig will consider it as a namespaced template for another file name

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

by stof at 2012-07-14T17:16:45Z

@alessandro1997 the issue is that namespaces are optional

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

by alessandro1997 at 2012-07-14T17:17:07Z

@stof Oh, right. I didn't get that :-)

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

by gunnarlium at 2012-07-14T17:20:32Z

@stof Ok, I see. So what we want is a symbol which is not allowed as a filename? Or (suboptimally) just add a requirement that template filenames can't contain certain reserved symbols?

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

by fabpot at 2012-07-14T17:23:37Z

But then, who is using `#` in a filename?

Anyway, I'm going to implement a version based on PHP streams to stick to the PHP way. Using a PHP stream might also allow us to get rid of the array loader.

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

by alessandro1997 at 2012-07-14T17:24:01Z

@gunnarlium But how would we check if the user is using reserved symbols in template names? Twig isn't aware of the available templates' names until the user requests them. And when he/she does it's too late because Twig doesn't know if the separator is used as namespace or if it's part of the filename.

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

by stof at 2012-07-14T17:33:38Z

@fabpot even if no sane guy would probably use ``#`` in a filename, it would mean that Twig assumes that all its userbase is sane :)

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

by lolautruche at 2012-07-14T18:51:53Z

-1 for #
+1 for php stream, though I agree with @jschreuder's arguments against it
+2 for @ syntax like in Symfony. I find it more consistent.

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

by fabpot at 2012-07-14T19:50:31Z

One problem with PHP streams is that it makes using template names quite ugly and verbose:

    {% include 'twig://namespace/index.html' %}

And for non-namespaced templates:

    {% include 'twig:///index.html' %}

for which we can provide a shortcut:

    {% include 'index.html' %}

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

by fabpot at 2012-07-14T19:54:35Z

If we are using `@` like in Symfony, it will be:

    {% include '@namespace/index.html' %}

And for non-namespaced templates:

    {% include 'index.html' %}

And for Symfony users, the notation would be the same as for resources. If we register each bundle path as a namespace, the path would even be exactly the same:

    {% include '@AcmeDemoBundle/Resources/views/layout.html.twig' %}

EDIT: that's not so simple because of the templates stored under `app/`.

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

by mahono at 2012-07-14T19:56:54Z

might not be the best idea, but what about using Backslash as namespace char?

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

by fabpot at 2012-07-14T19:57:50Z

@mahono: I have not dared to propose this alternative ;)

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

by fabpot at 2012-07-14T20:06:17Z

I've just made an additional commit that implements the `@namespace/template_path` notation.

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

by Baachi at 2012-07-14T20:32:41Z

The `@` syntax is the most consistent solution.
But the integration in symfony2 is really hard and a BC break.

The stream syntax is not a good solution.
`twig` might already be already registered as a stream.

I would suggest the `::` syntax.
2012-09-16 16:34:28 +02:00
Fabien Potencier f311c9579d fixed typo 2012-09-16 15:21:03 +02:00
Javier Lopez 5c805a1bb4 Update doc/intro.rst
How to load Twig using Composer
2012-09-16 14:08:03 +02:00
Pascal Borreli 2c1be8f0fd Fixed typo
http://english.stackexchange.com/questions/3640/is-substract-versus-subtract-a-proper-word
2012-09-12 08:29:08 +00:00
Fabien Potencier 68b8c4619c added a small clarification in the doc 2012-09-07 15:42:22 +02:00
Fabien Potencier 459720ff3b added more information about single-quoted vs double-quoted strings 2012-08-31 09:12:18 +02:00
Tomasz Ducin 682b0aa81c improved twig docs: twig for templates designers, NetBeans PHP IDE supports twig natively from 7.2 2012-08-28 22:41:01 +02:00
Fabien Potencier 37e7ba7575 fixed CS 2012-08-24 14:10:43 +02:00
Arne Kiesewetter ca3b1566e3 Added Highlighter for Notepad++ to the list 2012-08-24 12:41:34 +03:00
Konstantin G Romanov d5df200c75 * bug fixes.
* str_split on empty delimeter.
* tests and documentation updated.
2012-08-21 15:13:47 +04:00
Tyler King e3c201ad55 Added "split" filter aka explode. 2012-08-18 20:52:25 +04:00
Massimiliano Arione fce92f84d5 Update doc/templates.rst
Komodo and Komodo Edit have builtin Twig support since last version (7.1)
2012-08-17 18:14:24 +03:00
Sergi de Pablos b98fff166e Added missing abs and date_modify functions to the filters toctree 2012-08-07 10:31:19 +02:00
Fabien Potencier 942607245c tweaked documentation 2012-07-22 13:52:31 +02:00
Fabien Potencier c34541dfb3 changed notation of namespaced templates to @namespace/template_path 2012-07-22 13:52:31 +02:00
Fabien Potencier 0eb4d01d92 added namespaced templates support in Twig_Loader_Filesystem 2012-07-22 13:52:31 +02:00
Fabien Potencier c24ea1bcc1 added Twig_Loader_Filesystem::prependPath() 2012-07-22 13:52:09 +02:00
Albert Casademont ee87848751 Little typo 2012-07-19 14:03:26 +03:00
Albert Casademont c31dd7bccb The empty test now also checks for empty arrays 2012-07-19 14:00:01 +03:00
Fabien Potencier 1d1b949150 fixed typo in previous merge 2012-07-18 23:05:29 +02:00
Fabien Potencier 54b88bb647 merged branch Nami-Doc/patch-1 (PR #773)
Commits
-------

a6f03bd Reverse argument for number_format

Discussion
----------

Reverse argument for number_format

Just a little fix, the doc isn't following twig/php's argument order
2012-07-18 23:03:43 +02:00
Fabien Potencier b896ad82ce merged branch havvg/patch-1 (PR #777)
Commits
-------

0869d15 fix example autoescape for javascript

Discussion
----------

fix example autoescape for javascript

{% autoescape js %} triggers an exception "An escaping strategy must be a string or a Boolean in .."
2012-07-18 23:00:28 +02:00
Fabien Potencier d70860f5f5 added a note about accessing variable attributes that contains operators (closes #775) 2012-07-18 09:53:29 +02:00
Toni Uebernickel 0869d155db fix example autoescape for javascript
{% autoescape js %} triggers an exception "An escaping strategy must be a string or a Boolean in .."
2012-07-17 17:52:07 +03:00
Nami-Doc a6f03bd5c1 Reverse argument for number_format 2012-07-15 14:50:43 +03:00
Fabien Potencier 17e2c36a58 refactored the loader documentation 2012-07-14 16:10:03 +02:00
Fabien Potencier 0d5a639937 fixed the template escaper guesser example 2012-07-13 08:40:06 +02:00
Fabien Potencier e862905708 clarified usage of the string and array loaders 2012-07-13 08:31:08 +02:00
Douglas Greenshields 4e4d41b0d0 improved English in example text 2012-06-29 20:16:04 +02:00
Fabien Potencier 7657c01e65 added support for more escaping strategies (url, css, and html_attr) 2012-06-27 09:26:36 +02:00
Fabien Potencier cd049dac38 tweaked previous commit 2012-06-26 18:24:26 +02:00
Fabien Potencier 5758be0334 merged branch Seldaek/date_modify (PR #757)
Commits
-------

ae85586 Add docs for date_modify
0366cf6 Fix docs of date filter

Discussion
----------

Date modify filter

This is probably possible via `date(foo)|modify('-1day')|format()`, but it's non obvious and a dedicated filter might be a bit more prominent.

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

by fabpot at 2012-06-22T07:01:32Z

Just a quick thought: As it modifies the date, it should probably be a function, not a filter.

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

by stof at 2012-06-22T07:24:52Z

@fabpot Aren't filters meant to transform the value ?
2012-06-26 18:23:42 +02:00
Andreas Hucks f8406701e5 clarified documentation of pre_escape option 2012-06-25 19:09:27 +02:00
Jordi Boggiano ae85586e6f Add docs for date_modify 2012-06-20 19:45:35 +02:00
Jordi Boggiano 0366cf6185 Fix docs of date filter 2012-06-20 19:45:27 +02:00
Fabien Potencier 4618d75318 fixed typos 2012-06-14 17:02:35 +02:00
Fabien Potencier 0d5dbedef5 fixed escaping when a project defines a function named html or js (closes #724) 2012-06-14 17:00:45 +02:00
Fabien Potencier 4c9e394c38 added some information about template recompilation (closes #743) 2012-06-14 15:20:28 +02:00
Fabien Potencier 073cfd0180 tweaked doc 2012-06-14 15:15:52 +02:00
Fabien Potencier 793660510f fixed doc (closes #744) 2012-06-14 15:07:01 +02:00
Adrien Brault 80a2a7ea1d [Doc] Fix some typos 2012-06-13 01:27:42 +03:00
Fabien Potencier 6d072640c4 added Komodo to the list of supported IDEs 2012-05-31 07:17:23 +02:00
Fabien Potencier 12dff669ef added Coda 2 in the list of supported IDEs 2012-05-30 22:55:03 +02:00
Fabien Potencier b6e417ecf7 merged branch maartendekeizer/master (PR #738)
Commits
-------

f0a0036 Add abs filter including unit test and documentation

Discussion
----------

Add abs filter to Twig

With abs it is possible to make negative values positive and leave positive values positive.

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

by maartendekeizer at 2012-05-26T19:02:34Z

Example when using abs

{% if days_left < 0 %}
    {{ days_left|abs }} days to late!
{% else %}
    {{ days_left }} days left
{% endif %}

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

by stof at 2012-05-26T19:12:43Z

I'm not sure about adding this filter in the core. I think it would be better in the Twig-extensions repo. @fabpot thoughts ?

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

by maartendekeizer at 2012-05-26T21:18:47Z

@stof abs is a really basic/natural function it belongs to the base mathematic functions. If this was an implementation of for example the ABC-formula or Pythagoras it must be in the extension repo., but abs is more core related I think.

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

by fabpot at 2012-05-27T07:11:33Z

Can you add some unit tests and squash your commits? Thanks.

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

by maartendekeizer at 2012-05-27T14:40:56Z

First time squashing commits; learned something new :-). I will add a unit test tomorrow.

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

by maartendekeizer at 2012-05-27T17:36:58Z

Unit test and documentation added.

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

by fabpot at 2012-05-27T18:41:25Z

After fixing the markup issue, you will have to squash again ;)

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

by maartendekeizer at 2012-05-27T20:44:29Z

Done

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

by fabpot at 2012-05-28T19:19:55Z

Looks like you have not squash your commits.

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

by maartendekeizer at 2012-05-28T20:05:34Z

@fabot you want one commit for the complete pr?

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

by fabpot at 2012-05-28T20:06:53Z

For such a PR, yes.
2012-05-28 22:54:16 +02:00
Maarten de Keizer f0a0036892 Add abs filter
including unit test and documentation
2012-05-28 22:27:26 +02:00