smarty-php / smarty

Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
Other
2.25k stars 707 forks source link

compileAllTemplates() has problems with block plugins #231

Closed SlimDeluxe closed 8 years ago

SlimDeluxe commented 8 years ago

I am using compileAllTemplates() for gettext extraction, but I just found out that it does not work with custom block functions. While the template works perfectly as expected, the following error is returned when using compileAllTemplates()

/var/www/project/com_saop/_frontend/views/---saop/orders/dispatch_by_product.tpl ------>Error: Syntax error in template "file:/var/www/project/com_saop/_frontend/views/saop/orders/dispatch_by_product.tpl" on line 79 "{/block}" unclosed {block} tag

Line 79 is {/block}, while the whole layout is like this:

{extends tpl('1column.tpl', '_frontend')}

{block page_body}
        {datatable class='table-striped' list=$list}
            <thead>
                bla...
            </thead>
            <tbody>
                bla...
            </tbody>
            <tfoot>
                bla...
            </tfoot>
        {/datatable}
{/block}

If I remove the {block page_body} wrapper and not use an extends statement (ie. remove inheritance), it still does not work, but the error is different:

------>Error: Syntax error in template "file:/var/www/project/com_saop/_frontend/views/saop/orders/dispatched.tpl" on line 77 "{/datatable}" unexpected closing tag

Running on dev-master.

Regards

uwetews commented 8 years ago

I could reproduce your problem. Was the block plugin 'datatable' in the plugins folder by file block.datatable.php? What happens if you replace 'datatable' with another block plugin like 'textformat'?

I have modified compileAllTemplates() to clear all internal caches for each template to eliminate every chance of side effects from compilation of other templates. The update is in the dev-master branch. Any feedback is welcome.

SlimDeluxe commented 8 years ago

Sorry I have found out the problem was in an old plugin function.datatable I have in one of the plugin dirs (it is not a block plugin)... Before using compileAllTemplates() I use setPluginsDir() which I though removes all plugins from other packages (each package has it own plugins dir). While it does remove the directories, it does not "unload" any already loaded plugins, so this was the problem. I have renamed the function now and everything works again.

However there's a code problem with your latest commit:

A PHP Error was encountered

Severity: 4096

Message: Argument 2 passed to Smarty_Internal_Method_CompileAllTemplates::compileAllTemplates() must be an instance of Smarty, string given

Filename: sysplugins/smarty_internal_method_compilealltemplates.php

Line Number: 35

A PHP Error was encountered

Severity: 4096

Message: Argument 1 passed to Smarty_Internal_Method_CompileAllTemplates::compileAll() must be an instance of Smarty, string given, called in /var/www/dev/vendor/smarty/smarty/libs/sysplugins/smarty_internal_method_compilealltemplates.php on line 38 and defined

Filename: sysplugins/smarty_internal_method_compilealltemplates.php

Line Number: 53

( ! ) Fatal error: Call to a member function getTemplateDir() on string in /var/www/dev/vendor/smarty/smarty/libs/sysplugins/smarty_internal_method_compilealltemplates.php on line 62 Call Stack Time Memory Function Location 1 0.0000 240304 {main}( ) .../backend.php:0 2 0.0014 289432 require_once( '/var/www/dev/_backend/core/SDLX_CodeIgniter.php' ) .../backend.php:208 3 0.1926 1435752 call_user_func_array:{/var/www/dev/_backend/core/SDLX_CodeIgniter.php:370} ( ) .../SDLX_CodeIgniter.php:370 4 0.1926 1436040 Maintainance->gettext_compile( ) .../SDLX_CodeIgniter.php:370 5 0.1929 1439736 Utilities->gettext_compile( ) .../maintainance.php:180 6 0.2143 1645808 compileAllTemplates ( ) .../Utilities.php:243 7 0.2143 1646296 Smarty_Internal_Data->__call( ) .../Utilities.php:243 8 0.2143 1646592 Smarty_Internal_Extension_Handler->_callExternalMethod( ) .../smarty_internal_data.php:241 9 0.2145 1650320 call_user_func_array:{/var/www/dev/vendor/smarty/smarty/libs/sysplugins/smarty_internal_extension_handler.php:96} ( ) .../smarty_internal_extension_handler.php:96 10 0.2145 1650872 Smarty_Internal_Method_CompileAllTemplates->compileAllTemplates( ) .../smarty_internal_extension_handler.php:96 11 0.2158 1659832 Smarty_Internal_Method_CompileAllTemplates->compileAll( ) .../smarty_internal_method_compilealltemplates.php:38

uwetews commented 8 years ago

you must update to the complete dev-master version because of some other internal changes.

SlimDeluxe commented 8 years ago

Not sure what you mean by that, my composer.json is "smarty/smarty": "dev-master" so I have the latest commit. Switching to one commit before that "smarty/smarty": "dev-master#dccfc6c2f5f519ff2db1b24de2ccb0283554b8c7" makes it work again

uwetews commented 8 years ago

If I install "smarty/smarty": "dev-master" at my place everything is okay. Have you tried not to update but reinstall Smarty by composer?

SlimDeluxe commented 8 years ago

I don't know what's the difference, but I tried it anyway. Deleted "smarty/smarty" from composer.json. Ran "composer update" which removed the smarty folder. Then put it back as "dev-master". Ran update again and the same errors are shown.

I've taken a look at line 35 of sysplugins/smarty_internal_method_compilealltemplates.php

public function compileAllTemplates(Smarty $dummy, Smarty $smarty, $extension = '.tpl', $force_compile = false, $time_limit = 0,
                                        $max_errors = null)

If I change this to

public function compileAllTemplates(Smarty $smarty, $extension = '.tpl', $force_compile = false, $time_limit = 0,
                                        $max_errors = null)

(removed $dummy param) it seems to be working again.

uwetews commented 8 years ago

the fix is now in the master branch

ophian commented 8 years ago

@uwetews What about the same in compileAllConfig(Smarty $dummy, Smarty $smarty, ...)? And they both are also noted in the PHPDoc header.

uwetews commented 8 years ago

@ophian Ian you are right both methods are new fixed in the master branch