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