Class humhub\components\rendering\ViewPathRenderer

Inheritancehumhub\components\rendering\ViewPathRenderer » yii\base\BaseObject
Implementshumhub\components\rendering\Renderer
Subclasseshumhub\components\rendering\DefaultViewPathRenderer, humhub\components\rendering\LayoutRenderer, humhub\components\rendering\MailLayoutRenderer, humhub\components\rendering\MailRenderer, humhub\modules\activity\components\ActivityMailRenderer, humhub\modules\activity\components\ActivityWebRenderer, humhub\modules\notification\renderer\MailRenderer, humhub\modules\notification\renderer\WebRenderer
Available since version1.2

A ViewPathRenderer is a simple Renderer implementation for rendering Viewables by searching for a matching viewFile relative to the Viewables class path or relative to a given $viewPath.

If a $viewPath is given the renderer will search for the view within this path directly.

If no $viewPath is given, the ViewPathRenderer will determine the view path relative to the Viewable as following:

  • In case $parent = false the renderer will search directly in the class path subdirectory views:

viewableClassPath/views

  • in case $parent = true the renderer will search in the parents views folder (e.g. in the modules main view folder):

viewableClassPath/../views

  • in case $subPath is given the subPath will be appended to the view path e.g:

For a subPath 'mail' and $parent = false the search path will be: viewableClassPath/views/mail

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$parent boolean If set to true the renderer will search in the parents view directory for the view. humhub\components\rendering\ViewPathRenderer
$subPath string A subpath within the view folder used for searching the view e. humhub\components\rendering\ViewPathRenderer
$viewPath string View path humhub\components\rendering\ViewPathRenderer

Public Methods

Hide inherited methods

MethodDescriptionDefined By
getViewFile() Returnes the viewFile of the given Viewable. humhub\components\rendering\ViewPathRenderer
getViewPath() Returns the directory containing the view files for this event. humhub\components\rendering\ViewPathRenderer
render() Renders the viewable by searching the viewable's viewName within the given viewPath. humhub\components\rendering\ViewPathRenderer
renderView() Helper function for rendering a Viewable with the given viewParams. humhub\components\rendering\ViewPathRenderer

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
suffix() Checks if the given $viewName has a file suffix or not. humhub\components\rendering\ViewPathRenderer

Property Details

$parent public property

If set to true the renderer will search in the parents view directory for the view.

public boolean $parent false
$subPath public property

A subpath within the view folder used for searching the view e.g mails. This will only be used if $viewPath is not given.

public string $subPath null
$viewPath public property

View path

public string $viewPath null

Method Details

getViewFile() public method

Returnes the viewFile of the given Viewable.

public string|null getViewFile ( humhub\components\rendering\Viewable $viewable )
$viewable humhub\components\rendering\Viewable
return string|null

The view filename or null when not exists

getViewPath() public method

Returns the directory containing the view files for this event.

The default implementation returns the 'views' subdirectory under the directory containing the notification class file.

public string getViewPath ( humhub\components\rendering\Viewable $viewable, $useSubPath true )
$viewable humhub\components\rendering\Viewable

The viewable

$useSubPath boolean

Use the subpath if provided

return string

The directory containing the view files for this notification.

render() public method

Renders the viewable by searching the viewable's viewName within the given viewPath.

If no viewPath is given this function uses '../views/viewName' as view file path.

public string render ( humhub\components\rendering\Viewable $viewable, $params = [] )
$viewable humhub\components\rendering\Viewable
$params
throws \humhub\components\rendering\ViewNotFoundException

if the view file does not exist

renderView() public method

Helper function for rendering a Viewable with the given viewParams.

public \humhub\components\rendering\type renderView ( humhub\components\rendering\Viewable $viewable, $viewParams )
$viewable humhub\components\rendering\Viewable
$viewParams \humhub\components\rendering\type
suffix() protected method

Checks if the given $viewName has a file suffix or not.

If the viewName does not have a suffix we assume a php file and append '.php'.

protected string suffix ( $viewName )
$viewName string
return string

VieName with suffix.