Joomla - enqueueMessage,前端有标题和关闭按钮

时间:2013-11-09 01:23:01

标签: php joomla joomla3.2

我正在使用

从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方法可以做到这一点,还是我必须想出办法?

2 个答案:

答案 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);
    ....

您可以在https://github.com/Digital-Peak/DPAttachments/blob/master/com_dpattachments/admin/libraries/dpattachments/core.php#L162

找到代码