简体   繁体   English

当使用elseif条件时,Phalcon的Volt引擎在jQuery块中生成错误

[英]Phalcon's Volt engine generates error in jQuery block when using elseif conditional

I'm getting weird PHP error when using Phalcon's Volt engine in my project. 在项目中使用Phalcon的Volt引擎时,我收到奇怪的PHP错误。 The case seems to be very simple but although I have checked my code many times I can't seem to get working the simple if-elseif-endif structure. 这种情况似乎很简单,但是尽管我检查了很多次代码,但似乎无法使用简单的if-elseif-endif结构。

The template code is here, it is placed in Javascript block in context of jQuery callcack function: 模板代码在这里,它放在jQuery callcack函数上下文中的Javascript块中:

{% if table.form.rendered_in == 'offcanvas' %}
            //offcanvas form
            //set attributes

            $(row).find('td.edit-control').

                attr('data-source', '{{table.form.full_action_url}}?get_form').
                attr('data-canvas', 'body').
                attr('data-target', '#rightSlider').
                attr('data-toggle', 'offcanvas').

                click(function () { 
                    console.log('! show edit form: '+record_id);    
                    //edit_one(record_id);
                    if (!right_offcanvas_visible) {

                        //request form with ajax
                        var url = $(this).attr('data-source');
                        var data = {
                            'choose_record': [record_id]
                        };

                        //console.log('Serialized data: '+data);    
                        //$('div#rightSlider').offcanvas('show');
                        TASK.Ajax.Post(url, data, function(response) {  
                            $('div#rightSlider').find('div.rightSliderContent').html(response);
                            //$('div.offcanvas').offcanvas({canvas: 'body'}); // todo: make it work!
                            console.log('! edit one record form set up');    
                        });

                    }

                });

            //delete    
            $(row).find('td.delete-control').

                attr('data-source', '{{table.form.full_action_url}}?get_delete_form').
                attr('data-canvas', 'body').
                attr('data-target', '#rightSlider').
                attr('data-toggle', 'offcanvas').

                click(function () { 
                    if (!right_offcanvas_visible) {

                        //request form with ajax
                        var url = $(this).attr('data-source');
                        var data = {
                            'choose_record': [record_id]
                        };

                        TASK.Ajax.Post(url, data, function(response) {  
                            $('div#rightSlider').find('div.rightSliderContent').html(response);
                        });

                    }

                });

        {% elseif table.form.rendered_in == 'page' %}
            //on same page above the table

            $(row).find('td.edit-control').
                attr('data-source', '{{table.form.full_action_url}}?get_form').
                click(function () { 
                    console.log('! show edit form above table: '+record_id);    
                    var url = $(this).attr('data-source');
                    var data = {
                        'choose_record': [record_id]
                    };

                    TASK.Ajax.Post(url, data, function(response) {  
                        $('div#form-page-main').html(response);
                        $('html, body').animate({ //scroll smoothly to form
                            scrollTop: $('div#form-page-main').offset().top - config.scrollDistanceFromTop
                        }, config.timeAnimateToAjaxForm);
                    });

                });            


            $(row).find('td.delete-control').
                attr('data-source', '{{table.form.full_action_url}}?get_delete_form').
                click(function () { 
                    console.log('! show delete form above table: '+record_id);    
                    var url = $(this).attr('data-source');
                    var data = {
                        'choose_record': [record_id]
                    };

                    TASK.Ajax.Post(url, data, function(response) {  
                        $('div#form-page-main').html(response);
                        $('html, body').animate({ //scroll smoothly to confirmation
                            scrollTop: $('div#form-page-main').offset().top - config.scrollDistanceFromTop
                        }, config.timeAnimateToAjaxForm);
                    });

                });

        {% elseif table.form.rendered_in == 'modal' %}
            // rendered in modal window

            $(row).find('td.edit-control').
                attr('data-source', '{{table.form.full_action_url}}?get_form').
                attr('data-target', '#largeModal').
                attr('data-toggle', 'modal').
                click(function () { 
                    console.log('! show edit form in modal: '+record_id);    
                    var url = $(this).attr('data-source');
                    var data = {
                        'choose_record': [record_id]
                    };

                    TASK.Ajax.Post(url, data, function(response) {  
                        $('div#largeModal').find('div.modal-body').html(response);
                    });

                });            


            $(row).find('td.delete-control').
                attr('data-source', '{{table.form.full_action_url}}?get_delete_form').
                attr('data-target', '#smallModal').
                attr('data-toggle', 'modal').
                click(function () { 
                    console.log('! show delete form in modal: '+record_id);    
                    var url = $(this).attr('data-source');
                    var data = {
                        'choose_record': [record_id]
                    };

                    TASK.Ajax.Post(url, data, function(response) {  
                        $('div#smallModal').find('div.modal-body').html(response);
                    });

                });

        {% endif %}

The error is generated possibly by Volt compiler at first elseif referenced below, volt file doesn't get compiled into PHP. 错误可能是由Volt编译器首先生成的,否则以下引用,否则volt文件未编译到PHP中。

{% elseif table.form.rendered_in == 'page' %}

The error says: Unexpected ENDIF in .../app/views/partials/grideditor.volt on line 307 错误提示: 307行... / app / views / partials / grideditor.volt中出现意外的ENDIF

The if-elseif-endif structure works nicely elsewhere in Javascript blocks. if-elseif-endif结构可在Javascript块中的其他地方很好地工作。 Which makes things even more odd is that when I replace the elseif with multiple if-endif, if-endif, ... as below, everything works fine. 更加奇怪的是,当我用多个if-endif,if-endif ...替换elseif时,如下所示,一切正常。

{% if table.form.rendered_in == 'offcanvas' %}
            //offcanvas form
            //set attributes

            $(row).find('td.edit-control').

                attr('data-source', '{{table.form.full_action_url}}?get_form').
                attr('data-canvas', 'body').
                attr('data-target', '#rightSlider').
                attr('data-toggle', 'offcanvas').

                click(function () { 
                    console.log('! show edit form: '+record_id);    
                    //edit_one(record_id);
                    if (!right_offcanvas_visible) {

                        //request form with ajax
                        var url = $(this).attr('data-source');
                        var data = {
                            'choose_record': [record_id]
                        };

                        //console.log('Serialized data: '+data);    
                        //$('div#rightSlider').offcanvas('show');
                        TASK.Ajax.Post(url, data, function(response) {  
                            $('div#rightSlider').find('div.rightSliderContent').html(response);
                            //$('div.offcanvas').offcanvas({canvas: 'body'}); // todo: make it work!
                            console.log('! edit one record form set up');    
                        });

                    }

                });

            //delete    
            $(row).find('td.delete-control').

                attr('data-source', '{{table.form.full_action_url}}?get_delete_form').
                attr('data-canvas', 'body').
                attr('data-target', '#rightSlider').
                attr('data-toggle', 'offcanvas').

                click(function () { 
                    if (!right_offcanvas_visible) {

                        //request form with ajax
                        var url = $(this).attr('data-source');
                        var data = {
                            'choose_record': [record_id]
                        };

                        TASK.Ajax.Post(url, data, function(response) {  
                            $('div#rightSlider').find('div.rightSliderContent').html(response);
                        });

                    }

                });

        {% endif %}


        {% if table.form.rendered_in == 'page' %}
            //on same page above the table

            $(row).find('td.edit-control').
                attr('data-source', '{{table.form.full_action_url}}?get_form').
                click(function () { 
                    console.log('! show edit form above table: '+record_id);    
                    var url = $(this).attr('data-source');
                    var data = {
                        'choose_record': [record_id]
                    };

                    TASK.Ajax.Post(url, data, function(response) {  
                        $('div#form-page-main').html(response);
                        $('html, body').animate({ //scroll smoothly to form
                            scrollTop: $('div#form-page-main').offset().top - config.scrollDistanceFromTop
                        }, config.timeAnimateToAjaxForm);
                    });

                });            


            $(row).find('td.delete-control').
                attr('data-source', '{{table.form.full_action_url}}?get_delete_form').
                click(function () { 
                    console.log('! show delete form above table: '+record_id);    
                    var url = $(this).attr('data-source');
                    var data = {
                        'choose_record': [record_id]
                    };

                    TASK.Ajax.Post(url, data, function(response) {  
                        $('div#form-page-main').html(response);
                        $('html, body').animate({ //scroll smoothly to confirmation
                            scrollTop: $('div#form-page-main').offset().top - config.scrollDistanceFromTop
                        }, config.timeAnimateToAjaxForm);
                    });

                });

        {% endif %}


        {% if table.form.rendered_in == 'modal' %}
            // rendered in modal window

            $(row).find('td.edit-control').
                attr('data-source', '{{table.form.full_action_url}}?get_form').
                attr('data-target', '#largeModal').
                attr('data-toggle', 'modal').
                click(function () { 
                    console.log('! show edit form in modal: '+record_id);    
                    var url = $(this).attr('data-source');
                    var data = {
                        'choose_record': [record_id]
                    };

                    TASK.Ajax.Post(url, data, function(response) {  
                        $('div#largeModal').find('div.modal-body').html(response);
                    });

                });            


            $(row).find('td.delete-control').
                attr('data-source', '{{table.form.full_action_url}}?get_delete_form').
                attr('data-target', '#smallModal').
                attr('data-toggle', 'modal').
                click(function () { 
                    console.log('! show delete form in modal: '+record_id);    
                    var url = $(this).attr('data-source');
                    var data = {
                        'choose_record': [record_id]
                    };

                    TASK.Ajax.Post(url, data, function(response) {  
                        $('div#smallModal').find('div.modal-body').html(response);
                    });

                });

        {% endif %}

I'm using Phalcon 1.3.3 TS on Windows (x86, PHP 5.4.19) 我在Windows(x86,PHP 5.4.19)上使用Phalcon 1.3.3 TS

Any suggestions are very appreciated! 任何建议都非常感谢! Thanks! 谢谢!

You can start php inside volt and do those things, what volt don't provide. 您可以在volt内启动php并执行那些不提供volt的事情。

i believe in future we will have 我相信将来我们会

{% literal %} {% endliteral %} 
or
{% verbatim %} {% endverbatim %}

there is already NFR in github: https://github.com/phalcon/cphalcon/issues/1253 github中已经有NFR: https//github.com/phalcon/cphalcon/issues/1253

Now i can't find any wayout, just to use pure php in this part like: 现在,我找不到任何出路,只是在这一部分使用纯PHP,例如:

...
<?php
 // your code like it would be simple *.php file
?>
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM