在我的項目中使用Phalcon的Volt引擎時,出現奇怪的PHP錯誤。這種情況似乎很簡單,但儘管我多次檢查過我的代碼,但似乎無法使用簡單的if-elseif-endif結構。當使用elseif條件時,Phalcon的Volt引擎在jQuery塊中產生錯誤
模板代碼是在這裏,它被放置在Javascript塊的jQuery callcack功能方面:
{% 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 %}
可能是由伏在編譯下面引用第一ELSEIF產生的誤差,伏文件沒有得到編譯成PHP。
{% elseif table.form.rendered_in == 'page' %}
錯誤說: 在... /應用/視圖/諧音/上線307
的grideditor.volt意外ENDIF IF-ELSEIF - ENDIF結構很好地工作在別處JavaScript代碼段。這使得事情更加奇怪的是,當我用多個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 %}
我使用爾康1.3.3 TS(在Windows x86上,PHP 5.4.19)
任何建議都非常讚賞!謝謝!
{%literal%}在伏特上不存在,也沒有{%verbatim%} – Surt 2015-07-14 08:04:33
謝謝,更新了我的答案。 – 2015-07-14 08:35:03