how to use JHTML::_('behavior.modal') in Joomla?

蓝咒 提交于 2019-12-03 09:14:27

You can use this function to get a modal button

static public function getModalButtonObject($name,$text,$link,$width=750,$height=480)
{
    JHTML::_('behavior.modal', "a.{$name}");  // load the modal behavior for the name u given
        $buttonMap = new JObject();   // create an Jobject which will contain some data, it is similar like stdClass object
        $buttonMap->set('modal', true);
        $buttonMap->set('text', $text );
        $buttonMap->set('name', 'image');
        $buttonMap->set('modalname', $name);
        $buttonMap->set('options', "{handler: 'iframe', size: {x: ".$width.", y: ".$height."}}");
        $buttonMap->set('link', $link);
        return $buttonMap;
}

And HTML can be written as

<a id="<?php echo $buttonMap->modalname; ?>" class="<?php echo $buttonMap->modalname; ?>" title="<?php echo $buttonMap->text; ?>" href="<?php echo $buttonMap->link; ?>" rel="<?php echo $buttonMap->options; ?>"><?php echo $buttonMap->text; ?></a>

It doesn't have to be anywhere near that complicated. Many templates turn the modal behavior on already, but if they don't all you need to do is add this to the head -

<?php JHTML::_('behavior.modal'); ?>

Then add this to any links you want to open in a modal window -

class="modal"

Everything else is optional.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!