Summary about pagekit's view

    • Helpful

    Controller

    Globals

    Variable Description Instance of
    $app Main application object Application
    $view View object
    $view() or $view->render(): render template
    $view->{global}: get a global parameter
    $view->{helper}(): get the helper object
    $view->{helper}(*args): call a helper shortcut (__invoke() method)
    $view->{helper}()->{method}(*args): call a helper method
    View
    $theme Config of the enabled theme - (Array)
    $intl Internationalization module
    $intl->getLocale()
    IntlModule
    $params Parameters passed from the controller ArrObject


    Helpers

    $view->{helper}() Description Instance of Module
    menu Render a menu
    __invoke($name, $view = null, array $parameters = [])
    MenuHelper system/site
    position Render a (widget) position
    __invoke($name, $view = null, array $parameters = [])
    Positionhelper system/widget
    styles Add styles. Proxies all method calls to the AssetManager.
    __invoke($name, $source = null, $dependencies = [], $options = [])
    StylesHelper view
    scripts Add scripts. Proxies all method calls to the AssetManager.
    __invoke($name, $source = null, $dependencies = [], $options = [])
    ScriptsHelper "
    url Utility to handle url and roures. Proxies all calls to the UrlProvider
    UrlHelper "
    markdown Markdown parser
    __invoke($text)
    MarkdownHelper "
    section Set a section or define one with start and end commands, which can be used later again.
    start($name)
    stop($show = false)
    SectionHelper "
    token Displays a hidden token field to reduce the risk of CSRF exploits.
    get($name = '_csrf')
    TokenHelper "
    data Container for data which has to be converted to a script tag in which the data is initiated as a javascript variable (e.g. to use in Vue.js)
    add($name, $value)
    DataHelper "
    map Maps an string identifier to a template path. They can be used in $view->render()
    add($name, $path = null)
    MapHelper "
    meta Renders meta tags
    add($name, $value = '')
    MetaHelper "
    defer Defers a render call to right before the response
    __invoke($name)
    DeferredHelper "
    gravatar Get either a Gravatar URL or complete image tag for a specified email address.
    __invoke($email, $params = [])
    GravatarHelper "


    Events

    Every call to $view->render($name, array $parameters = []) triggers an event which has the identifier 'view.$name'. If a mapping of $name in the MapHelper is set, then this string is used for $name.


    This allows to overwrite every part, with listening to these events, of your rendered view. That's quite powerful.

    To ensure, that every render event identifier is unique, you can define a resource in your extension's index.php (e.g. 'myxtension:' => '').

    Then you can manipulate each render like this:

    Code
    1. 'events' => [
    2. 'view.myextension:views/path/to/my/template' => function ($event, $view) use ($app) {
    3. //do whatever you wand with View $view or ViewEvent $event
    4. $event->setTemplate('myotherextension:views/my/path')
    5. $view->meta()->add('title','Hacked view')
    6. }
    7. ]


    Event Description Triggered
    view.init Initiate view View.php l.52
    view.head
    Head is rendered $view->render('head')
    The head render is deferred $view->defer('head'), so actually the head is rendered on reponse. This guarantees, that scripts, style and data which are added during rendering the template, are also present.
    - view.meta Metas from MetaHelper are rendered after view.head
    - view.scripts Scripts from ScriptHelper are rendered "
    - view.styles Styles from StyleHelper are rendered "
    - view.data Datas from DataHelper is rendered "
    view.content Content is rendered $view->render('content')
    view.footer Footer is rendered $view->render('footer')
    view.messages Messages are rendered $view->render('messages')

    The LORD is my strength and my shield; in him my heart trusts, and I am helped; my heart exults, and with my song I give thanks to him. Psalm 28,7

    Edited 14 times, last by SAB ().

  • Feel free to contribute. I just ran through the code and collected everything important. I did not test anything, but I hope this overview help in templating!

    The LORD is my strength and my shield; in him my heart trusts, and I am helped; my heart exults, and with my song I give thanks to him. Psalm 28,7