Twig integration - i-MSCP 1.3.x

  • Some info for Twig integration (i-MSCP 1.3.x)

    For PHP action scripts, you must

    • Remove any reference to the iMSCP_pTemplate engine (variables are now stored in a specific variables container through a view model which can be retrieved via the registry ($viewModel = iMSCP_Registry::get('viewModel');))
    • Move translation strings at the template level
    • Try to move any presentation logic at the template level (e.g: html tags, value humanization and so on...)
    • Remove all arguments passed-in to the on*ScriptEnd event

    Note: The template to render is automatically detected, based on the PHP action script basename. However, if the template basename is different than the PHP action script basename, the detection will fail. In such a case, you can at your choice:

    • Specify the template to render manually through the view model ($viewModel->setTemplate('<template_to_render>');)
    • Rename the template to fit with the PHP action script basename

    For templates, you must

    • Rename the template from *.tpl to *.twig
    • See the For PHP action scripts, you must and Example sections for the rest

    Global variables that are always availables in the templates

    • iMSCP.config Hold configuration parameters from the imscp.conf file (parameter names are lowercased)
    • iMSCP.identity Identity object of the logged user
    • ...

    Note: Your own variables are accessible through the view variable inside the template. For instance:


    PHP action script level

    PHP
    1. ...$viewModel = iMSCP_Registry::get('viewModel');$viewModel->setVariable('my_variable', 'my_value');...


    Template level

    HTML
    1. ...
    2. <h1>{{ view.my_variable }}</h1>
    3. ...


    Custom filters that are availables in the templates

    • idna Decode ASCII domain names and email addresses. For instance, the xn--brger-kva.com ASCII domain name will be decoded to bürger.com
    • tr_status Translate status (toadd, tochange ...)
    • tr_limit Translate limit values, including feature values
    • bytesHuman Humanize byte values
    • int Get variable integer (this call intval() internally)

    Custom functions that are available in the templates

    • trn Return string plural. For instance, trn('%d cat in the place', '%d cats in the place', view.countCats)
    • tr Translate a string and process substitution if any. For instance: tr(trn('%d cat in the place', '%d cats in the place', view.count_cats), view.count_cats)
    • tr_datatables Return datatables plugin translations as json object
    • systemHas* functions. For instance, systemHasResellers(), systemHasCustomers() ...
    • resellerHas* functions. For instance, resellerHasFeature('subdomains') ...
    • customerHas* functions. For instance, customerHasFeature('subdomains') ...

    Examples


    Look at admin/admin_add.php and admin/admin.twig for concret example.


    See also: http://twig.sensiolabs.org/documentation


    For any question, feel free to ask in that thread.

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206

  • Note:


    Atm, I takes care of all admin/* scripts and associated templates. If you want help, you must in order:

    • Fork the 1.3.x branch and install it (on a dev server)
    • Say us which part you will do
    • Do a pull request once done

    Be aware that only pages which were already converted are working.

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206

  • Cancelled. We prefer work on v2.

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206