Back to Bootstrap class

Method renderModal

public static string
renderModal
(mixed $selector = 'modal', mixed $options = [], mixed $body = '')
Method to render a Bootstrap modal
Parameters
  • string $selector The ID selector for the modal. Expects a valid ID without the #!
  • array $options An array of options for the modal.
  • string $body Markup for the modal body. Appended after the `<iframe>` if the URL option is set
Returns
  • string HTML markup for a modal
Since
  • 3.0
Class: Bootstrap
Project: Joomla

Method renderModal - Source code

/**
 * Method to render a Bootstrap modal
 *
 * @param   string  $selector  The ID selector for the modal. Expects a valid ID without the #!
 * @param   array   $options   An array of options for the modal.
 * @param   string  $body      Markup for the modal body. Appended after the `<iframe>` if the URL option is set
 *
 * @return  string  HTML markup for a modal
 *
 * @since   3.0
 *
 * Options for the modal can be:
 * - backdrop     string|  true   Includes a modal-backdrop element. Alternatively, specify static
 *                boolean          for a backdrop which doesn't close the modal on click.
 * - keyboard     boolean  true   Closes the modal when escape key is pressed
 * - focus        boolean  true   Closes the modal when escape key is pressed
 * - title        string   null   The modal title
 * - closeButton  boolean  true   Display modal close button (default = true)
 * - footer       string   null   Optional markup for the modal footer
 * - url          string   null   URL of a resource to be inserted as an `<iframe>` inside the modal body
 * - height       string   null   Height of the `<iframe>` containing the remote resource
 * - width        string   null   Width of the `<iframe>` containing the remote resource
 */
public static function renderModal($selector = 'modal', $options = [], $body = '') : string
{
    // Only load once
    if (!empty(static::$loaded[__METHOD__][$selector])) {
        return '';
    }
    // Initialise with the Joomla specifics
    $options['isJoomla'] = true;
    // Include Basic Bootstrap component
    HTMLHelper::_('bootstrap.modal', '#' . preg_replace('/^[\\.#]/', '', $selector), $options);
    $layoutData = ['selector' => $selector, 'params' => $options, 'body' => $body];
    static::$loaded[__METHOD__][$selector] = true;
    return LayoutHelper::render('libraries.html.bootstrap.modal.main', $layoutData);
}