Please enable JavaScript to view this site.

The manual for the JobRouter developer

Navigation: SDK > Examples

Create Html Output

Scroll Prev Top Next More

Example

This example uses a template.html file with placeholders. The Html is imported in PHP as a string, the placeholders are replaced with variables and at the end the Html string is echoed to the screen.

index.php

<?php

use JobRouter\Sdk\UserManagerInterface;

use JobRouter\Sdk\PathsInterface;

 

return function (UserManagerInterface $userInterface, PathsInterface $pathsInterface): void {

 

    try {

 

        $user = $userInterface->getCurrentUser();

         

         // Load the HTML template

         $template = file_get_contents(__DIR__ . '/template.html');

         

         // Example data

         $employeeData = [

                 'fullname' => $user->getFullName(),

                 'phone' => $user->getPhone(),

                 'email' => $user->getEmail(),

                 'language' => $user->getLanguage(),

                 'region' => $user->getTimezone(),

                 'avatarImage' => $pathsInterface->getJobRouterUrl() . '/' . $user->getAvatarUrl(),

                 'department' => $user->getDepartment(),

                 'groupMemberships' => $user->getJobFunctions(),

                 'supervisor' => $userInterface->getUserByUsername($user->getSupervisor())->getFullName(),

                 'active' => $user->isBlocked() ? 'No' : 'Yes'

         ];

 

         // Convert group memberships to list items

         $groupList = '';

         foreach ($employeeData['groupMemberships'] as $group) {

                 $groupList .= "<li>$group</li>\n";

         }

         $employeeData['groupMemberships'] = $groupList;

 

         // Replace placeholders in the template

         foreach ($employeeData as $key => $value) {

                 $template = str_replace("#{" . $key . "}", $value, $template);

         }

 

         // Output the final profile page

         echo $template;

 

    } catch (\JobRouterException) {

         echo '<h3 style="color: #f44;">The user is not authenticated!</h3>';

    }

};

template.html

<!DOCTYPE html>

<html lang="de">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Employee Profile</title>

    <style>

        body {

            font-family: Arial, sans-serif;

            margin: 0;

            padding: 40px;

            background-color: #eef1f5;

            display: flex;

            justify-content: center;

            align-items: center;

            height: 100vh;

        }

        .profile-container {

            width: 100%;

            max-width: 600px;

            background: #ffffff;

            padding: 20px;

            border-radius: 10px;

            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);

            display: flex;

            align-items: flex-start;

        }

        .avatar-container {

            flex: 0 0 150px;

            text-align: center;

            padding-right: 20px;

        }

        .avatar {

            width: 120px;

            height: 120px;

            border-radius: 50%;

            border: 3px solid #007bff;

        }

        .details {

            flex: 1;

        }

        .section {

            margin-bottom: 20px;

            padding-bottom: 10px;

            border-bottom: 1px solid #ddd;

        }

        .section:last-child {

            border-bottom: none;

        }

        .section-title {

            font-size: 18px;

            font-weight: bold;

            color: #007bff;

            margin-bottom: 10px;

        }

        .info {

            margin-bottom: 10px;

            font-size: 16px;

            color: #333;

            display: flex;

        }

        .label {

            font-weight: bold;

            color: #007bff;

            min-width: 150px;

        }

        .groups {

            list-style-type: none;

            padding: 0;

            margin: 0;

        }

        .groups li {

            background: #f8f9fa;

            padding: 8px;

            margin-top: 5px;

            border-radius: 5px;

            font-size: 14px;

        }

    </style>

</head>

<body>

    <div class="profile-container">

        <div class="avatar-container">

            <img class="avatar" src="#{avatarImage}" alt="Profilbild">

        </div>

        <div class="details">

            <div class="section">

                <div class="section-title">Personal data</div>

                <div class="info"><span class="label">Name:</span> <span>#{fullname}</span></div>

                <div class="info"><span class="label">Language:</span> <span>#{language}</span></div>

                <div class="info"><span class="label">Region:</span> <span>#{region}</span></div>

                <div class="info"><span class="label">Department:</span> <span>#{department}</span></div>

                <div class="info"><span class="label">Supervisor:</span> <span>#{supervisor}</span></div>

                <div class="info">

                    <span class="label">Active:</span> 

                    <span class="status">#{active}</span>

                </div>

            </div>

            <div class="section">

                <div class="section-title">Contact details</div>

                <div class="info"><span class="label">Phone:</span> <span>#{phone}</span></div>

                <div class="info"><span class="label">Email:</span> <span>#{email}</span></div>

            </div>

            <div class="section">

                <div class="section-title">Group Memberships</div>

                <ul class="groups">

                    #{groupMemberships}

                </ul>

            </div>

        </div>

    </div>

</body>

</html>

Output

SDK_Examples_Html