This website uses Cookies to provide you with the best possible service. Please see our Privacy Policy for more information. Click the check box below to accept cookies. Then confirm with a click on "Save".  
Status: 2022-10-20

Frontend


Template Engine Smarty

myMVC makes use of the robust Template Engine Smarty.

All Templates you define in your module's template folder.

myMVC provides a standard set of template files if you create your module via myMVC.phar (see: Creating a Module). Below you can see the directory structure of the standard set of templates.

templates directory structure (assuming module is Foo)

modules/Foo/templates/
└── Frontend
    ├── content
    │   ├── 404.tpl
    │   ├── _cookieConsent.tpl
    │   ├── index.tpl
    │   └── _noscript.tpl
    └── layout
        ├── footer.tpl
        ├── header.tpl
        ├── index.tpl
        └── menu.tpl

Smarty
For more Information about how to code templates with powerful Smarty Template Engine please visit the official Website https://www.smarty.net/

View

assign any variable to your template

assign any variable to your template (assuming module is Foo)

\Foo\View\Index::init()->assign('myFrontendVariable', 'Any Content');

In your template you can access that assigned variable this way:

{$myFrontendVariable}

autoAssign variables

If you created your module via myMVC.phar (see: Creating a Module) or you added additional context information to your route by yourself, you can easily auto assign all additional route infos:

autoAssign variables to template (assuming module is Foo)

\Foo\View\Index::init()->autoAssign(
    Route::getCurrent()
);

render

render the template (assuming module is Foo)

\Foo\View\Index::init()->render();

Accessing Class methods and objects in smarty template

You can access any myMVC Class directly in the templates.

Examples

// gives BasePath
{MVC\Config::get_MVC_BASE_PATH()}

// debugs additional info of the current route object
{MVC\Debug::info(MVC\Route::getCurrent()->get_additional())}

Also you can access methods of assigned Objects:

Example

{$oDTRoutingAdditional->get_sContent()}