[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Layout/ -> LayoutHelper.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Layout;
  11  
  12  // phpcs:disable PSR1.Files.SideEffects
  13  \defined('JPATH_PLATFORM') or die;
  14  // phpcs:enable PSR1.Files.SideEffects
  15  
  16  /**
  17   * Helper to render a Layout object, storing a base path
  18   *
  19   * @link   https://docs.joomla.org/Special:MyLanguage/Sharing_layouts_across_views_or_extensions_with_JLayout
  20   * @since  3.1
  21   */
  22  class LayoutHelper
  23  {
  24      /**
  25       * A default base path that will be used if none is provided when calling the render method.
  26       * Note that FileLayout itself will defaults to JPATH_ROOT . '/layouts' if no basePath is supplied at all
  27       *
  28       * @var    string
  29       * @since  3.1
  30       */
  31      public static $defaultBasePath = '';
  32  
  33      /**
  34       * Method to render a layout with debug info
  35       *
  36       * @param   string  $layoutFile   Dot separated path to the layout file, relative to base path
  37       * @param   mixed   $displayData  Object which properties are used inside the layout file to build displayed output
  38       * @param   string  $basePath     Base path to use when loading layout files
  39       * @param   mixed   $options      Optional custom options to load. Registry or array format
  40       *
  41       * @return  string
  42       *
  43       * @since   3.5
  44       */
  45      public static function debug($layoutFile, $displayData = null, $basePath = '', $options = null)
  46      {
  47          $basePath = empty($basePath) ? self::$defaultBasePath : $basePath;
  48  
  49          // Make sure we send null to FileLayout if no path set
  50          $basePath = empty($basePath) ? null : $basePath;
  51          $layout = new FileLayout($layoutFile, $basePath, $options);
  52  
  53          return $layout->debug($displayData);
  54      }
  55  
  56      /**
  57       * Method to render the layout.
  58       *
  59       * @param   string  $layoutFile   Dot separated path to the layout file, relative to base path
  60       * @param   mixed   $displayData  Object which properties are used inside the layout file to build displayed output
  61       * @param   string  $basePath     Base path to use when loading layout files
  62       * @param   mixed   $options      Optional custom options to load. Registry or array format
  63       *
  64       * @return  string
  65       *
  66       * @since   3.1
  67       */
  68      public static function render($layoutFile, $displayData = null, $basePath = '', $options = null)
  69      {
  70          $basePath = empty($basePath) ? self::$defaultBasePath : $basePath;
  71  
  72          // Make sure we send null to FileLayout if no path set
  73          $basePath = empty($basePath) ? null : $basePath;
  74          $layout = new FileLayout($layoutFile, $basePath, $options);
  75  
  76          return $layout->render($displayData);
  77      }
  78  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer