我正在使用
从ajax调用返回通知$app = JFactory::getApplication();
$app->enqueueMessage('Joomla notice', 'info');
在前端,这会产生以下结果(注意空标题):
<div id="system-message-container">
<div id="system-message" class="alert alert-info">
<h4 class="alert-heading"></h4>
<div>
<p>Joomla notice </p>
</div>
</div>
</div>
但是我想要显示带有标题和解雇按钮的通知,就像它在后端一样,即
<div id="system-message-container">
<button type="button" class="close" data-dismiss="alert">×</button>
<div class="alert alert-info">
<h4 class="alert-heading">Info</h4>
<p>Joomla notice</p>
</div>
</div>
是否有Joomla方法可以做到这一点,还是我必须想出办法?
答案 0 :(得分:2)
消息由media/system/js/core.js
函数在Joomla.renderMessages
中呈现。
您可以使用
jQuery(function() {
Joomla.renderMessages = function(messages) {
// copy / adapt the original function here.
}
});
此外,可以通过html/message.php
模板覆盖来自定义非ajax消息。
答案 1 :(得分:2)
在您收到消息后,我建议发送消息,如
echo new JResponseJson($data);
JFactory::getApplication()->close();
然后,您可以在客户端处理消息数组,如@ Riccardo的解决方案。例如,我的ajax成功函数看起来像
success: function(responseText){
var json = jQuery.parseJSON(responseText);
Joomla.renderMessages(json.messages);
....
找到代码