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

前端 未结 2 893
醉酒成梦
醉酒成梦 2021-02-11 08:23

I am creating a component,

controllers
    theatercontroller
    facilitycontroller
Models
    theater
    facility
view
    theater
    facility
相关标签:
2条回答
  • 2021-02-11 09:10

    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>
    
    0 讨论(0)
  • 2021-02-11 09:22

    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.

    0 讨论(0)
提交回复
热议问题