NetLife Guru

Leveraging `import{}` for Standalone Applications with a Routing System

In a standalone application that doesn't rely on an external framework, using the import feature can be extremely beneficial, especially for managing page-specific meta tags and other components. This approach enhances the flexibility and modularity of each page within your application.

Example of Structuring Routes with `import`:

Consider a routing structure like the following in your standalone PHP application:


    $templateEngine->setRoutes([
        '*' => [
            '/layout.html',
            '/components/header.html',
            '/components/footer.html',
            '/components/forms.html',
        ],
        '' => [
            '/pages/index.html',
        ],
        'docs' => [
            '/pages/docs.html',
        ],
        'contact' => [
            '/pages/contact.html',
        ],
    ]);

Dynamic Meta Tag Management:

In each specific page, like docs.html, you can define meta tags or other necessary head elements within a block, say {meta}:


    {meta}
      {$title = "Dynamic Title for Docs Page"}
      {$description = "Description specific to Docs Page"}
    {/meta}

By utilizing import in your layout.html, you can dynamically include these meta tags into the head of your HTML structure:


    <!DOCTYPE html>
    <html lang="{$lang}">
    <head>
        {import{meta}}
        <title>{$title}</title>
        <meta name="description" content="{$description}">
        <!-- Other head elements -->
    </head>
    <body>
        include{header}
        <!-- Page Content -->
        include{footer}
    </body>
    </html>

Advantages: