FOF30\View\ViewTemplateFinder::getViewTemplateUris PHP Метод

getViewTemplateUris() публичный Метод

Returns a list of template URIs for a specific component, view, template and sub-template. The $parameters array can have any of the following keys: component string The name of the component, e.g. com_something view string The name of the view layout string The name of the layout tpl string The name of the subtemplate strictView bool Should I only look in the specified view, or should I look in the pluralised/singularised view as well? strictLayout bool Should I only look for this layout, or also for the default layout? strictTpl bool Should I only look for this subtemplate or also for no subtemplate? sidePrefix string The application side prefix (site, admin, auto, any)
public getViewTemplateUris ( array $parameters ) : array
$parameters array See above
Результат array
    public function getViewTemplateUris(array $parameters)
    {
        // Merge the default parameters with the parameters given
        $parameters = array_merge(array('component' => $this->container->componentName, 'view' => $this->view->getName(), 'layout' => $this->defaultLayout, 'tpl' => $this->defaultTpl, 'strictView' => $this->strictView, 'strictLayout' => $this->strictLayout, 'strictTpl' => $this->strictTpl, 'sidePrefix' => $this->sidePrefix), $parameters);
        $uris = array();
        $component = $parameters['component'];
        $view = $parameters['view'];
        $layout = $parameters['layout'];
        $tpl = $parameters['tpl'];
        $strictView = $parameters['strictView'];
        $strictLayout = $parameters['strictLayout'];
        $strictTpl = $parameters['strictTpl'];
        $sidePrefix = $parameters['sidePrefix'];
        $basePath = $sidePrefix . ':' . $component . '/' . $view . '/';
        $uris[] = $basePath . $layout . ($tpl ? "_{$tpl}" : '');
        if (!$strictTpl) {
            $uris[] = $basePath . $layout;
        }
        if (!$strictLayout) {
            $uris[] = $basePath . 'default' . ($tpl ? "_{$tpl}" : '');
            if (!$strictTpl) {
                $uris[] = $basePath . 'default';
            }
        }
        if (!$strictView) {
            $parameters['view'] = $this->container->inflector->isSingular($view) ? $this->container->inflector->pluralize($view) : $this->container->inflector->singularize($view);
            $parameters['strictView'] = true;
            $extraUris = $this->getViewTemplateUris($parameters);
            $uris = array_merge($uris, $extraUris);
            unset($extraUris);
        }
        return array_unique($uris);
    }

Usage Example

Пример #1
0
 /**
  * Our function uses loadAnyTemplate to provide smarter view template loading.
  *
  * @param   string  $tpl    The name of the template file to parse
  * @param   boolean $strict Should we use strict naming, i.e. force a non-empty $tpl?
  *
  * @return  mixed  A string if successful, otherwise an Exception
  */
 public function loadTemplate($tpl = null, $strict = false)
 {
     $result = '';
     $uris = $this->viewFinder->getViewTemplateUris(array('component' => $this->container->componentName, 'view' => $this->getName(), 'layout' => $this->getLayout(), 'tpl' => $tpl, 'strictTpl' => $strict));
     foreach ($uris as $uri) {
         try {
             $result = $this->loadAnyTemplate($uri);
             break;
         } catch (\Exception $e) {
             $result = $e;
         }
     }
     if ($result instanceof \Exception) {
         $this->container->platform->raiseError($result->getCode(), $result->getMessage());
     }
     return $result;
 }