Twig, the flexible, fast, and secure template language for PHP

Overview

Twig, the flexible, fast, and secure template language for PHP

Twig is a template language for PHP, released under the new BSD license (code and documentation).

Twig uses a syntax similar to the Django and Jinja template languages which inspired the Twig runtime environment.

Sponsors

Blackfire.io

More Information

Read the documentation for more information.

Comments
  • Bump minimum version to PHP 5.6

    Bump minimum version to PHP 5.6

    Twig 2.0 will be released really soon now (hopefully by the end of the year). So, it's time again to reconsider the minimum PHP version we want to support.

    I would like to bump it to PHP 5.6 for the following reasons:

    • PHP 5.5 is not supported anymore (not even security fixes now);

    • the latest Ubuntu LTS is already using PHP 7!

    • #2228 allows to improve performance significantly and having this without the ifstatement makes the optimization more interesting.

    What do you think?

    opened by fabpot 49
  • added namespaced templates support in Twig_Loader_Filesystem

    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).

    opened by fabpot 44
  • Undefined offset: 0

    Undefined offset: 0

    Hello,

    since f2e5f40 I get An exception has been thrown during the rendering of a template ("Notice: Undefined offset: 0"). which makes it impossible to display any template. The problem comes from the modification made in lib/Twig/Profiler/NodeVisitor/Profiler.php.

    I don't have a solution nor an idea as to why it crashes, I hope someone can fix this quickly.

    opened by Soviann 41
  • [1.28] Deprecated warning when using macro which is imported in parent template

    [1.28] Deprecated warning when using macro which is imported in parent template

    base.html.twig:

    {% import "macro.html.twig" as macro %}
    
    {% block content '' %}
    

    child.html.twig:

    {% extends 'base.html.twig' %}
    
    {% block content %}
        {{ macro.foo() }}
    {% endblock %}
    

    Warning:

    Deprecated: Using the dot notation on an instance of __CLASS is deprecated since version 1.28 and won't be supported anymore in 2.0.

    Is this expected behavior? There is no warning, when I import the macro in child.html.twig again.

    Macros 
    opened by gharlan 41
  • [PHP Extension] Bug when the object implements \ArrayAccess

    [PHP Extension] Bug when the object implements \ArrayAccess

    There is a bug when using the PHP extension and trying to access a public property of an object implementing the \ArrayAccess interface.

    Using the following object:

    <?php
    
    class TwigTest implements \ArrayAccess
    {
        public $vars;
        private $data;
    
        public function __construct()
        {
            $this->vars = array('foo' => 1);
            $this->data = array('bar' => 1);
        }
    
        public function offsetExists($offset)
        {
            return array_key_exists($offset, $this->data);
        }
    
        public function offsetGet($offset)
        {
            if (!$this->offsetExists($offset)) {
                throw new \RuntimeException("Offset '$offset' does not exist !");
            }
    
            return $this->data[$offset];
        }
    
        public function offsetSet($offset, $value)
        {
            $this->data[$offset] = $value;
        }
    
        public function offsetUnset($offset)
        {
            unset($this->data[$offset]);
        }
    }
    

    and trying to access the vars property from a template:

    <?php
    // Controller    
        /**
         * @Template
         */
        public function testAction()
        {
            return array(
                'view'      => new TwigTest(),
            );
        }
    
    {# test.html.twig #}
    
    {{ dump(view.vars) }}
    

    The error message is: Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("Offset 'vars' does not exist !")

    It means that the code is using the \ArrayAccess interface to get the value when it should directly access the public property on the object.

    This error is caused by the PHP extension (it does not occur when the extension is not enabled). I have managed to narrow down the root cause to the TWIG_PROPERTY() call in the extension.

    If you look at the body of the function, you'll see calls to TWIG_GET_ARRAY_ELEMENT which should be the root cause of the issue. We should only be returning the value of the property at this place as it is done by the PHP code.

    I don't know the internals of PHP enough in order to come with a proper fix so any help with debugging this would be much appreciated.

    Related issues:

    • symfony/symfony#5064
    • #668
    opened by vicb 37
  • PHP7 support on Twig extension

    PHP7 support on Twig extension

    I saw Twig extension is now tested against PHP7 but compile failed :

    phpize-7.0.0
    ./configure --with-php-config=/usr/bin/php-config-7.0.0 --enable-twig
    make
    

    Leads to :

    make
    /bin/sh /usr/src/build/php/Twig/ext/twig/libtool --mode=compile cc  -I. -I/usr/src/build/php/Twig/ext/twig -DPHP_ATOM_INC -I/usr/src/build/php/Twig/ext/twig/include -I/usr/src/build/php/Twig/ext/twig/main -I/usr/src/build/php/Twig/ext/twig -I/usr/include/php/7.0.0/php -I/usr/include/php/7.0.0/php/main -I/usr/include/php/7.0.0/php/TSRM -I/usr/include/php/7.0.0/php/Zend -I/usr/include/php/7.0.0/php/ext -I/usr/include/php/7.0.0/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /usr/src/build/php/Twig/ext/twig/twig.c -o twig.lo
    mkdir .libs
     cc -I. -I/usr/src/build/php/Twig/ext/twig -DPHP_ATOM_INC -I/usr/src/build/php/Twig/ext/twig/include -I/usr/src/build/php/Twig/ext/twig/main -I/usr/src/build/php/Twig/ext/twig -I/usr/include/php/7.0.0/php -I/usr/include/php/7.0.0/php/main -I/usr/include/php/7.0.0/php/TSRM -I/usr/include/php/7.0.0/php/Zend -I/usr/include/php/7.0.0/php/ext -I/usr/include/php/7.0.0/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/src/build/php/Twig/ext/twig/twig.c  -fPIC -DPIC -o .libs/twig.o
    /usr/src/build/php/Twig/ext/twig/twig.c:23:40: error: ext/standard/php_smart_str.h: No such file or directory
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'TWIG_ARRAY_KEY_EXISTS':
    /usr/src/build/php/Twig/ext/twig/twig.c:100: warning: passing argument 2 of 'zend_hash_exists' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_hash.h:157: note: expected 'struct zend_string *' but argument is of type 'char *'
    /usr/src/build/php/Twig/ext/twig/twig.c:100: error: too many arguments to function 'zend_hash_exists'
    /usr/src/build/php/Twig/ext/twig/twig.c:102: error: 'IS_BOOL' undeclared (first use in this function)
    /usr/src/build/php/Twig/ext/twig/twig.c:102: error: (Each undeclared identifier is reported only once
    /usr/src/build/php/Twig/ext/twig/twig.c:102: error: for each function it appears in.)
    /usr/src/build/php/Twig/ext/twig/twig.c:110: warning: passing argument 2 of 'zend_symtable_exists' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_hash.h:372: note: expected 'struct zend_string *' but argument is of type 'char *'
    /usr/src/build/php/Twig/ext/twig/twig.c:110: error: too many arguments to function 'zend_symtable_exists'
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'TWIG_INSTANCE_OF_USERLAND':
    /usr/src/build/php/Twig/ext/twig/twig.c:128: warning: passing argument 1 of 'zend_lookup_class' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_execute.h:43: note: expected 'struct zend_string *' but argument is of type 'char *'
    /usr/src/build/php/Twig/ext/twig/twig.c:128: error: too many arguments to function 'zend_lookup_class'
    /usr/src/build/php/Twig/ext/twig/twig.c:128: warning: comparison between pointer and integer
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'TWIG_GET_ARRAYOBJECT_ELEMENT':
    /usr/src/build/php/Twig/ext/twig/twig.c:141: warning: passing argument 1 of 'zend_call_method' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_interfaces.h:41: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:141: warning: passing argument 6 of 'zend_call_method' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_interfaces.h:41: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:143: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_variables.h:111: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'TWIG_ISSET_ARRAYOBJECT_ELEMENT':
    /usr/src/build/php/Twig/ext/twig/twig.c:164: warning: passing argument 1 of 'zend_call_method' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_interfaces.h:41: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:164: warning: passing argument 6 of 'zend_call_method' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_interfaces.h:41: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:166: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_variables.h:111: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:175: error: 'IS_BOOL' undeclared (first use in this function)
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'TWIG_CALL_USER_FUNC_ARRAY':
    /usr/src/build/php/Twig/ext/twig/twig.c:206: warning: passing argument 2 of 'zend_hash_get_current_data_ex' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_hash.h:169: note: expected 'HashPosition *' but argument is of type 'void **'
    /usr/src/build/php/Twig/ext/twig/twig.c:206: error: too many arguments to function 'zend_hash_get_current_data_ex'
    /usr/src/build/php/Twig/ext/twig/twig.c:214:36: error: macro "ZVAL_STRING" passed 3 arguments, but takes just 2
    /usr/src/build/php/Twig/ext/twig/twig.c:214: error: 'ZVAL_STRING' undeclared (first use in this function)
    /usr/src/build/php/Twig/ext/twig/twig.c:217: error: incompatible types when assigning to type 'zval' from type 'struct zval *'
    /usr/src/build/php/Twig/ext/twig/twig.c:220: error: 'zend_fcall_info' has no member named 'object_ptr'
    /usr/src/build/php/Twig/ext/twig/twig.c:224: error: 'zend_fcall_info' has no member named 'retval_ptr_ptr'
    /usr/src/build/php/Twig/ext/twig/twig.c:226: warning: assignment from incompatible pointer type
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'TWIG_CALL_BOOLEAN':
    /usr/src/build/php/Twig/ext/twig/twig.c:248: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_variables.h:111: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'TWIG_GET_STATIC_PROPERTY':
    /usr/src/build/php/Twig/ext/twig/twig.c:261: warning: assignment makes pointer from integer without a cast
    /usr/src/build/php/Twig/ext/twig/twig.c:263: warning: passing argument 2 of 'zend_std_get_static_property' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_object_handlers.h:165: note: expected 'struct zend_string *' but argument is of type 'char *'
    /usr/src/build/php/Twig/ext/twig/twig.c:263: error: too many arguments to function 'zend_std_get_static_property'
    /usr/src/build/php/Twig/ext/twig/twig.c:263: warning: assignment from incompatible pointer type
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'TWIG_GET_ARRAY_ELEMENT_ZVAL':
    /usr/src/build/php/Twig/ext/twig/twig.c:284: warning: passing argument 2 of 'zend_hash_find' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_hash.h:152: note: expected 'struct zend_string *' but argument is of type 'char *'
    /usr/src/build/php/Twig/ext/twig/twig.c:284: error: too many arguments to function 'zend_hash_find'
    /usr/src/build/php/Twig/ext/twig/twig.c:287: error: 'IS_BOOL' undeclared (first use in this function)
    /usr/src/build/php/Twig/ext/twig/twig.c:291: error: too many arguments to function 'zend_hash_index_find'
    /usr/src/build/php/Twig/ext/twig/twig.c:295: warning: passing argument 2 of 'zend_symtable_find' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_hash.h:348: note: expected 'struct zend_string *' but argument is of type 'char *'
    /usr/src/build/php/Twig/ext/twig/twig.c:295: error: too many arguments to function 'zend_symtable_find'
    /usr/src/build/php/Twig/ext/twig/twig.c:316:42: error: macro "ZVAL_STRING" passed 3 arguments, but takes just 2
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'TWIG_GET_ARRAY_ELEMENT':
    /usr/src/build/php/Twig/ext/twig/twig.c:316: error: 'ZVAL_STRING' undeclared (first use in this function)
    /usr/src/build/php/Twig/ext/twig/twig.c:322: warning: passing argument 2 of 'zend_symtable_find' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_hash.h:348: note: expected 'struct zend_string *' but argument is of type 'char *'
    /usr/src/build/php/Twig/ext/twig/twig.c:322: error: too many arguments to function 'zend_symtable_find'
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'TWIG_PROPERTY':
    /usr/src/build/php/Twig/ext/twig/twig.c:334: error: too few arguments to function 'object->value.obj->handlers->read_property'
    /usr/src/build/php/Twig/ext/twig/twig.c:338: error: 'zend_executor_globals' has no member named 'uninitialized_zval_ptr'
    /usr/src/build/php/Twig/ext/twig/twig.c:375:40: error: macro "ZVAL_STRING" passed 3 arguments, but takes just 2
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'TWIG_PROPERTY_CHAR':
    /usr/src/build/php/Twig/ext/twig/twig.c:375: error: 'ZVAL_STRING' undeclared (first use in this function)
    /usr/src/build/php/Twig/ext/twig/twig.c:390:31: error: macro "ZVAL_STRING" passed 3 arguments, but takes just 2
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'TWIG_CALL_S':
    /usr/src/build/php/Twig/ext/twig/twig.c:390: error: 'ZVAL_STRING' undeclared (first use in this function)
    /usr/src/build/php/Twig/ext/twig/twig.c:394:34: error: macro "ZVAL_STRING" passed 3 arguments, but takes just 2
    /usr/src/build/php/Twig/ext/twig/twig.c:397: error: incompatible types when assigning to type 'zval' from type 'struct zval *'
    /usr/src/build/php/Twig/ext/twig/twig.c:400: error: 'zend_fcall_info' has no member named 'object_ptr'
    /usr/src/build/php/Twig/ext/twig/twig.c:404: error: 'zend_fcall_info' has no member named 'retval_ptr_ptr'
    /usr/src/build/php/Twig/ext/twig/twig.c:406: warning: assignment from incompatible pointer type
    /usr/src/build/php/Twig/ext/twig/twig.c:411: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_variables.h:111: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:415: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_variables.h:111: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'TWIG_CALL_SB':
    /usr/src/build/php/Twig/ext/twig/twig.c:425: error: 'IS_BOOL' undeclared (first use in this function)
    /usr/src/build/php/Twig/ext/twig/twig.c:428: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_variables.h:111: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:446:34: error: macro "ZVAL_STRING" passed 3 arguments, but takes just 2
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'TWIG_CALL_ZZ':
    /usr/src/build/php/Twig/ext/twig/twig.c:446: error: 'ZVAL_STRING' undeclared (first use in this function)
    /usr/src/build/php/Twig/ext/twig/twig.c:449: error: incompatible types when assigning to type 'zval' from type 'struct zval *'
    /usr/src/build/php/Twig/ext/twig/twig.c:452: error: 'zend_fcall_info' has no member named 'object_ptr'
    /usr/src/build/php/Twig/ext/twig/twig.c:456: error: 'zend_fcall_info' has no member named 'retval_ptr_ptr'
    /usr/src/build/php/Twig/ext/twig/twig.c:458: warning: assignment from incompatible pointer type
    /usr/src/build/php/Twig/ext/twig/twig.c:468: error: 'IS_BOOL' undeclared (first use in this function)
    /usr/src/build/php/Twig/ext/twig/twig.c:470: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_variables.h:111: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'TWIG_NEW':
    /usr/src/build/php/Twig/ext/twig/twig.c:485: warning: passing argument 1 of 'zend_lookup_class' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_execute.h:43: note: expected 'struct zend_string *' but argument is of type 'char *'
    /usr/src/build/php/Twig/ext/twig/twig.c:485: error: too many arguments to function 'zend_lookup_class'
    /usr/src/build/php/Twig/ext/twig/twig.c:485: warning: comparison between pointer and integer
    /usr/src/build/php/Twig/ext/twig/twig.c:489: error: lvalue required as left operand of assignment
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'twig_add_array_key_to_string':
    /usr/src/build/php/Twig/ext/twig/twig.c:506: error: 'smart_str' has no member named 'len'
    /usr/src/build/php/Twig/ext/twig/twig.c:510: error: 'zend_hash_key' has no member named 'nKeyLength'
    /usr/src/build/php/Twig/ext/twig/twig.c:515: error: 'zend_hash_key' has no member named 'arKey'
    /usr/src/build/php/Twig/ext/twig/twig.c:515: error: 'zend_hash_key' has no member named 'nKeyLength'
    /usr/src/build/php/Twig/ext/twig/twig.c:515: warning: passing argument 3 of 'php_addcslashes' from incompatible pointer type
    /usr/include/php/7.0.0/php/ext/standard/php_string.h:127: note: expected 'char *' but argument is of type 'int *'
    /usr/src/build/php/Twig/ext/twig/twig.c:515: error: too many arguments to function 'php_addcslashes'
    /usr/src/build/php/Twig/ext/twig/twig.c:515: warning: assignment from incompatible pointer type
    /usr/src/build/php/Twig/ext/twig/twig.c:516: warning: assignment makes pointer from integer without a cast
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'TWIG_IMPLODE_ARRAY_KEYS':
    /usr/src/build/php/Twig/ext/twig/twig.c:528: warning: excess elements in struct initializer
    /usr/src/build/php/Twig/ext/twig/twig.c:528: warning: (near initialization for 'collector')
    /usr/src/build/php/Twig/ext/twig/twig.c:531: warning: passing argument 2 of 'zend_hash_apply_with_arguments' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_hash.h:132: note: expected 'apply_func_args_t' but argument is of type 'int (*)(void *, int,  struct __va_list_tag *, struct zend_hash_key *)'
    /usr/src/build/php/Twig/ext/twig/twig.c:534: error: 'smart_str' has no member named 'c'
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'TWIG_RUNTIME_ERROR':
    /usr/src/build/php/Twig/ext/twig/twig.c:551: warning: passing argument 1 of 'zend_lookup_class' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_execute.h:43: note: expected 'struct zend_string *' but argument is of type 'char *'
    /usr/src/build/php/Twig/ext/twig/twig.c:551: error: too many arguments to function 'zend_lookup_class'
    /usr/src/build/php/Twig/ext/twig/twig.c:551: warning: comparison between pointer and integer
    /usr/src/build/php/Twig/ext/twig/twig.c:570:69: error: macro "ZVAL_STRINGL" passed 4 arguments, but takes just 3
    /usr/src/build/php/Twig/ext/twig/twig.c:570: error: 'ZVAL_STRINGL' undeclared (first use in this function)
    /usr/src/build/php/Twig/ext/twig/twig.c:571:33: error: macro "ZVAL_STRING" passed 3 arguments, but takes just 2
    /usr/src/build/php/Twig/ext/twig/twig.c:571: error: 'ZVAL_STRING' undeclared (first use in this function)
    /usr/src/build/php/Twig/ext/twig/twig.c:575:79: error: macro "ZVAL_STRINGL" passed 4 arguments, but takes just 3
    /usr/src/build/php/Twig/ext/twig/twig.c:576: warning: passing argument 2 of 'call_user_function' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_API.h:469: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:581: warning: passing argument 2 of 'call_user_function' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_API.h:469: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:581: warning: passing argument 6 of 'call_user_function' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_API.h:469: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:583: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_variables.h:111: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:584: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_variables.h:111: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:585: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_variables.h:111: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:586: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_variables.h:111: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'TWIG_GET_CLASS_NAME':
    /usr/src/build/php/Twig/ext/twig/twig.c:597: error: 'zend_uint' undeclared (first use in this function)
    /usr/src/build/php/Twig/ext/twig/twig.c:597: error: expected ';' before 'class_name_len'
    /usr/src/build/php/Twig/ext/twig/twig.c:603: error: 'class_name_len' undeclared (first use in this function)
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'twig_add_method_to_class':
    /usr/src/build/php/Twig/ext/twig/twig.c:624: warning: passing argument 1 of 'strlen' from incompatible pointer type
    /usr/include/string.h:397: note: expected 'const char *' but argument is of type 'struct zend_string *'
    /usr/src/build/php/Twig/ext/twig/twig.c:625: warning: passing argument 1 of '_estrndup' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_alloc.h:81: note: expected 'const char *' but argument is of type 'struct zend_string *'
    /usr/src/build/php/Twig/ext/twig/twig.c:628: error: too many arguments to function 'add_assoc_stringl_ex'
    /usr/src/build/php/Twig/ext/twig/twig.c:649:116: error: macro "zend_unmangle_property_name" passed 4 arguments, but takes just 3
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'twig_add_property_to_class':
    /usr/src/build/php/Twig/ext/twig/twig.c:649: error: 'zend_unmangle_property_name' undeclared (first use in this function)
    /usr/src/build/php/Twig/ext/twig/twig.c:654:50: error: macro "add_assoc_string" passed 4 arguments, but takes just 3
    /usr/src/build/php/Twig/ext/twig/twig.c:654: error: 'add_assoc_string' undeclared (first use in this function)
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'twig_add_class_to_cache':
    /usr/src/build/php/Twig/ext/twig/twig.c:664: warning: assignment makes pointer from integer without a cast
    /usr/src/build/php/Twig/ext/twig/twig.c:673: warning: passing argument 2 of 'zend_hash_apply_with_arguments' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_hash.h:132: note: expected 'apply_func_args_t' but argument is of type 'int (*)(void *, int,  struct __va_list_tag *, struct zend_hash_key *)'
    /usr/src/build/php/Twig/ext/twig/twig.c:674: warning: passing argument 2 of 'zend_hash_apply_with_arguments' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_hash.h:132: note: expected 'apply_func_args_t' but argument is of type 'int (*)(void *, int,  struct __va_list_tag *, struct zend_hash_key *)'
    /usr/src/build/php/Twig/ext/twig/twig.c: In function 'zif_twig_template_get_attributes':
    /usr/src/build/php/Twig/ext/twig/twig.c:752: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_variables.h:111: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:831: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_variables.h:111: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:872: warning: passing argument 1 of 'zval_get_type' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_types.h:312: note: expected 'const struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:872: warning: initialization from incompatible pointer type
    /usr/src/build/php/Twig/ext/twig/twig.c:872: warning: passing argument 1 of 'zval_get_type' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_types.h:312: note: expected 'const struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:872: warning: passing argument 1 of '_convert_to_string' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_operators.h:242: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:876: warning: passing argument 1 of 'zval_get_type' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_types.h:312: note: expected 'const struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:876: warning: initialization from incompatible pointer type
    /usr/src/build/php/Twig/ext/twig/twig.c:876: warning: passing argument 1 of 'zval_get_type' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_types.h:312: note: expected 'const struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:876: warning: passing argument 1 of '_convert_to_string' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_operators.h:242: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:881: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_variables.h:111: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:1032:33: error: macro "ZVAL_STRING" passed 3 arguments, but takes just 2
    /usr/src/build/php/Twig/ext/twig/twig.c:1032: error: 'ZVAL_STRING' undeclared (first use in this function)
    /usr/src/build/php/Twig/ext/twig/twig.c:1036: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_variables.h:111: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:1056: warning: passing argument 1 of 'TWIG_INSTANCE_OF' from incompatible pointer type
    /usr/src/build/php/Twig/ext/twig/twig.c:114: note: expected 'struct zval *' but argument is of type 'struct zend_object *'
    /usr/src/build/php/Twig/ext/twig/twig.c:1086: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_variables.h:111: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:1088: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_variables.h:111: note: expected 'struct zval *' but argument is of type 'struct zval **'
    /usr/src/build/php/Twig/ext/twig/twig.c:1096: warning: passing argument 1 of '_zval_ptr_dtor' from incompatible pointer type
    /usr/include/php/7.0.0/php/Zend/zend_variables.h:111: note: expected 'struct zval *' but argument is of type 'struct zval **'
    make: *** [twig.lo] Error 1
    
    opened by odoucet 35
  • added the inline tag

    added the inline tag

    At Sensio, we manage websites with many mostly-static pages that share almost the same structure (with different content of course), but with some subtle differences. After trying many different possibilities (external templates, inheritance, macros, and some ugly ones that I won't even tell you about ;)) to structure our templates, we came to the conclusion that we needed a new concept.

    This new concept is implemented via a new tag, inline, which I want to include in Twig 1.8 (not for the upcoming 1.7 which is due this week). But before merging this code into master, I want to gather some feedback from the community. One of my questions being: Will you use this new possibility?

    I won't tell you more here as the tag is fully documented in the diff.

    opened by fabpot 34
  • Adding new operators/tests for strings comparison operations?

    Adding new operators/tests for strings comparison operations?

    In a CSS selector, you can easily check if a value start with/ends with/contains something:

    [att ^= val] – the “begins with” selector
    [att $= val] – the “ends with” selector
    [att *= val] – the “contains” selector
    

    In the new Symfony ExpressionLanguage component, there is also two operators (based on Perl) to check if a value matches something:

    attr =~ /regex/  {# regex #}
    attr !~ /regex/  {# not regex #}
    

    As you can see, the = sign is not at the same place in both examples.

    Another way to provide the same feature would be to add tests instead of operators:

    attr is startingwith(val)
    attr is endingwith(val)
    attr is containing(val)
    attr is matching(regex)
    
    attr is not startingwith(val)
    attr is not endingwith(val)
    attr is not containing(val)
    attr is not matching(regex)
    

    So, here are my questions:

    • Any interest in having this feature in Twig Core extension? or in a new extension in core? or in a new extension in Twig-extensions? or is that just too much?
    • Would it be better to have the feature implemented as operators (to be consistent with CSS selectors) or tests (probably easier to read/understand)?

    Note: If we were to implement this feature in Twig as tests, we would replace the Perl regex style operators in the Symfony component with the matching test instead.

    Thoughts?

    opened by fabpot 33
  • Error Cannot redeclare class Twig_Environment

    Error Cannot redeclare class Twig_Environment

    I updated vendors, and only update version twig.

     - Removing twig/twig (1.x-dev 460712d)
      - Installing twig/twig (1.x-dev 04ef7a1)
        Loading from cache
    

    But now I get the following error:

    FatalErrorException in Environment.php line 17: Error: Cannot redeclare class Twig_Environment

    I cleared cache... but the error continue... I did a compare two commits... but I dont see nothing unusual...

    https://github.com/twigphp/Twig/compare/460712d...04ef7a1#diff-d4416d290253c72cec40c63f54354b16

    any idea ?

    This is my composer

    	"require" : {
    		"php" : "^5.6|^7.0",
    		"ext-mcrypt" : "*",
    		"twig/extensions" : "^1.4",
    		"sensio/framework-extra-bundle" : "~3.0",
    		"sensio/generator-bundle" : "~3.0",
    		"symfony/assetic-bundle": "2.8.1",
    		"incenteev/composer-parameter-handler" : "~2.0",
    		"twbs/bootstrap" : "dev-master",
    		"knplabs/knp-paginator-bundle" : "dev-master",
    		"craue/formflow-bundle" : "2.1.8",
    		"shtumi/useful-bundle" : "dev-master",
    		"sonata-project/formatter-bundle" : "2.3.2",
    		"sonata-project/doctrine-extensions" : "1.0.2",
    		"frequence-web/contact-bundle" : "*",
    		"jms/serializer-bundle" : "^1.1",
            "sylius/sylius": "1.0.0-alpha.2",
    		"presta/sitemap-bundle" : "[email protected]",
    		"beelab/recaptcha2-bundle" : "1.2.1",
    		"dizda/cloud-backup-bundle" : "^3.2",
    		"aws/aws-sdk-php" : "2.8.24",
    		"lexik/maintenance-bundle" : "2.1.1",
    		"hwi/oauth-bundle" : "0.3.x",
    		"friendsofsymfony/rest-bundle" : "1.8.x",
    		"crevillo/payum-redsys" : "^1.0",
    		"payum/paypal-express-checkout-nvp" : "^1.3",
    		"php-http/guzzle6-adapter" : "^1.1",
    		"oyejorge/less.php": "v1.7.0.10",
    		"doctrine/doctrine-cache-bundle": "^1.3",
    		"predis/predis": "^1.1",
    		"snc/redis-bundle": "^2.0",
    		"knplabs/knp-gaufrette-bundle": "^0.3.0",
    		"liip/imagine-bundle": "1.7.2",
    		"phpdocumentor/reflection-docblock": "2.0.4"
    	},
    	"require-dev" : {
    		"raulfraile/ladybug-bundle" : "~1.0",
    		"behat/behat" : "~3.0",
    		"behat/symfony2-extension" : "[email protected]",
    		"behat/mink-extension" : "[email protected]",
    		"behat/mink-browserkit-driver" : "[email protected]",
    		"behat/mink-selenium2-driver" : "@dev",
    		"behat/mink" : "[email protected]",
    		"fzaninotto/faker" : "~1.2",
    		"phpunit/phpunit" : "<=5.7",
    		"visithor/visithor-bundle" : "^[email protected]",
    		"michaelmoussa/doctrine-qbmocker": "^0.12.0"
    	},
    
    opened by Chrysweel 30
  • Use

    Use "has" as trigger for tests

    I have a test that I can use as follows:

        {% if app.user is user_that_has_more_than_one_partner %}
    

    This is verbose, and I was wondering if it might not make more sense to create a has keyword that triggers a test like is does. That way, we could use:

        {% if app.user has more_than_one_partner %}
    

    Since has typically returns a boolean response, I would consider this useful in many more instances.

    opened by imctomhv 30
  • new tests to check variable type

    new tests to check variable type

    I didn't find any discussion about this, neither issues.

    What about adding to Twig core ests about the type of variable?

    It could be achieved in various way.

    1) many tests like:

    {% if var is string %}
    

    Looking at PHP gettype() function, I would suggest:

    {% if var is boolean %}
    {% if var is integer %}
    {% if var is double %}
    {% if var is string %}
    {% if var is array %}
    {% if var is object %}
    {% if var is resource %}
    

    2) a new filter:

    {% var | type %}
    

    | type filter would return a value specified in PHP gettype() function, letting it possible to use:

    {% if var | type is sameas('string') %}
    {% if var | type is sameas('array') %}
    ...
    

    3) a new comparison operator:

        {% if var is type of 'string' %}
    

    and

        {% if var is not type of 'string' %}
    

    I don't know which is preferable: 2) lets know the type of a var independently by being in a if statement 3) is more elegant but ca be used only in a if

    what do you think? maybe can be implemented both 2) and 3), they would be redundant only partially

    opened by inmarelibero 29
  • can i run this command without quotes?

    can i run this command without quotes?

    hello. thanks for this project. I don't know much about the twig template, but I'm participating in a ctf contest. In order to pass the level I have, I need to run the same command below without using quotes (single quotes, double quotes, backtick).

    example command: {{['id',1]|sort('system')|join}}

    The above command is used to run the "id" command in the linux operating system. but we need to not use any quotation marks to pass this level. is there a way i can run the above "id" command without quotes?

    opened by Phoenix1112 0
  • What happened to the shuffle filter?

    What happened to the shuffle filter?

    I believe shuffle was added to the old twig/extensions but now missing from the twig core extensions.

    What is the current position/status of the shuffle filter?

    opened by kitsguru 3
  • Updates CoreExtension::twig_constant to check for definition first to avoid hard crash

    Updates CoreExtension::twig_constant to check for definition first to avoid hard crash

    The behaviour of PHP's constant() method has been updated after https://github.com/php/php-src/issues/9905 was accepted and fixed in PHP 8.1 (and previously changed post PHP 8.0) . This PR prevents a fatal error in the case a constant is supplied that doesn't actually exist.

    opened by AMRoche 0
  • attribute, call macro

    attribute, call macro

    Hello,

    I would like to call macro via attribute function, where macro name will be variable, like this: {% set var=test %} {{ attribute(_self,var,[]) }} {% macro test() %} asd {% endmacro %}

    But, at this, when I call attribute funcrion, I got error message: [24-Oct-2022 00:36:58 Europe/Berlin] PHP Fatal error: Uncaught Twig\Error\RuntimeError: Variable "test" does not exist. in /var/www/twig/templates/complexExtends/fullCoreConfiguration.twig:1 Stack trace: #0 /var/www/twig/Twig/Environment.php(358) : eval()'d code(37): __TwigTemplate_91f65122729c67177b64bf63e9863a6c13ea15d037fb9fb61487aed7083f1fef->{closure}() #1 /var/www/twig/Twig/Template.php(394): __TwigTemplate_91f65122729c67177b64bf63e9863a6c13ea15d037fb9fb61487aed7083f1fef->doDisplay(Array, Array) #2 /var/www/twig/Twig/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array) #3 /var/www/twig/Twig/Template.php(379): Twig\Template->display(Array) #4 /var/www/twig/Twig/TemplateWrapper.php(40): Twig\Template->render(Array, Array) #5 /var/ho in /var/www/twig/templates/complexExtends/fullCoreConfiguration.twig on line 1

    Case, where I call macro via attribute and macro name is constant/string, works fine: {{ attribute(_self,'test',[]) }} {% macro test() %} asd {% endmacro %}

    Is there way, how can I call variable macro? Like as my first case?

    opened by Izolant 0
  • example needed: `registerUndefinedTokenParserCallback()`

    example needed: `registerUndefinedTokenParserCallback()`

    I am looking for a way to shim unknown tags from a loaded Twig file, while preserving internal nodes available to the parser/walker.

    Are there code examples of how to use registerUndefinedTokenParserCallback()? It's rather trivial to shim with registerUndefinedFunctionCallback() and registerUndefinedFilterCallback(), but I have not found a way to skip unknown tags.

    This code works for functions and filters, i.e. $env->registerUndefinedFunctionCallback(shimTwig(TwigFunction::class))

        function shimTwig(string $type) {
            return function ($name) use ($type) {
                return new $type($name);
            };
        }
    
    opened by therealpecus 0
PHP Template Attribute Language — template engine for XSS-proof well-formed XHTML and HTML5 pages

PHPTAL - Template Attribute Language for PHP Requirements If you want to use the builtin internationalisation system (I18N), the php-gettext extension

PHPTAL 174 Nov 12, 2022
Multi target HAML (HAML for PHP, Twig, )

Multi target HAML MtHaml is a PHP implementation of the HAML language which can target multiple languages. Currently supported targets are PHP and Twi

Arnaud Le Blanc 363 Nov 21, 2022
Twig Template Engine to Phalcon PHP

Twig Template Engine to Phalcon PHP

Vinicius 4 Oct 7, 2022
A complete and fully-functional implementation of the Jade template language for PHP

Tale Jade for PHP Finally a fully-functional, complete and clean port of the Jade language to PHP — Abraham Lincoln The Tale Jade Template Engine brin

Talesoft 92 Sep 20, 2022
Prosebot is a template-based natural language generation application

Prosebot is a template-based natural language generation application. Throughout the last years, ZOS has been developing Prosebot, alongside their collaboration with FEUP, as part of the zerozero.pt project.

Zerozero 13 Dec 2, 2022
A template abstraction prototype for PHP template engines

Schranz Templating A template abstraction prototype for PHP template engines. This project should help to find a way for a general Template Render Int

Schranz Templating 13 Nov 19, 2022
Experimental ActiveRecord layer on top of Doctrine2 using the Twig templating engine

This is an experiment for building ActiveRecord functionality on top of Doctrine2 using the Twig templating engine. Whether it is called Propel2 or not is irrelevant.

Francois Zaninotto 85 Dec 5, 2022
Provides TemplateView and TwoStepView using PHP as the templating language, with support for partials, sections, and helpers.

Aura View This package provides an implementation of the TemplateView and TwoStepView patterns using PHP itself as the templating language. It support

Aura for PHP 82 Apr 22, 2022
A PHP project template with PHP 8.1, Laminas Framework and Doctrine

A PHP project template with PHP 8.1, Laminas Framework and Doctrine

Henrik Thesing 3 Mar 8, 2022
The free-to-use template for your Imagehost-website made with PHP, HTML and CSS!

The free-to-use template for your Imagehost-website made with PHP, HTML and CSS! Some information before we start This repo is only code related, to a

Ilian 6 Jul 22, 2022
The free-to-use template for your Imagehost-website made with PHP, HTML and CSS!

The free-to-use template for your Imagehost-website made with PHP, HTML and CSS! Some information before we start This repo is only code related, to a

Ilian 6 Jul 22, 2022
⚡️ Simple and fastly template engine for PHP

EasyTpl ⚡️ Simple and fastly template engine for PHP Features It's simple, lightweight and fastly. No learning costs, syntax like PHP template It is s

PHPPkg 18 Sep 26, 2022
Foil brings all the flexibility and power of modern template engines to native PHP templates

Foil brings all the flexibility and power of modern template engines to native PHP templates. Write simple, clean and concise templates with nothing more than PHP.

Foil PHP 167 Dec 3, 2022
PHP template engine for native PHP templates

FOIL PHP template engine, for PHP templates. Foil brings all the flexibility and power of modern template engines to native PHP templates. Write simpl

Foil PHP 167 Dec 3, 2022
A SilverStripe Module with template methods to quickly make use of FocusPoint, LazySizes, and Object-fit

LazyFocusFit A SilverStripe module with template methods to quickly make use of FocusPoint, LazySizes and object-fit. Requirements PHP FocusPoint JS/C

Evans Hunt 9 Nov 4, 2022
Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.

Smarty 3 template engine smarty.net Documentation For documentation see www.smarty.net/docs/en/ Requirements Smarty can be run with PHP 5.2 to PHP 7.4

Smarty PHP Template Engine 2k Dec 1, 2022
Native PHP template system

Plates Plates is a native PHP template system that's fast, easy to use and easy to extend. It's inspired by the excellent Twig template engine and str

The League of Extraordinary Packages 1.3k Dec 3, 2022
View template engine of PHP extracted from Laravel

Blade 【简体中文】 This is a view templating engine which is extracted from Laravel. It's independent without relying on Laravel's Container or any others.

刘小乐 142 Oct 19, 2022
A ready-to-use Model View Controller template in PHP

PHP-MVC-Template A ready-to-use Model View Controller template in PHP Use this repo as a template! (Or clone it) Start to configure your MVC file Afte

Loule | Louis 19 Aug 30, 2022