Part on Templates is finished

This commit is contained in:
Patryk Hegenberg 2022-12-10 15:21:46 +01:00
parent a45a77f0ae
commit 9e01258040
2 changed files with 46 additions and 47 deletions

View file

@ -1,47 +1,25 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Demo</title>
</head>
<body>
<?php
$books = [
[
'name' => 'Do Androids Dream of Electric Sheep',
'author' => 'Philip K. Dick',
'releaseYear' => 1968,
'purchaseUrl' =>'http://example.com'
],
[
'name' => 'Projekt Hail Mary',
'author' => 'Andy Weir',
'releaseYear' => 2021,
'purchaseUrl' => 'http://example.com'
],
[
'name' => 'The Martian',
'author' => 'Andy Weir',
'releaseYear' => 2011,
'purchaseUrl' => 'http://example.com'
]
];
$filteredItems = array_filter($books, function($book) {
return $book['author'] == 'Andy Weir';
});
?>
<ul>
<?php foreach($filteredItems as $book): ?>
<li>
<a href="<?= $book['purchaseUrl']; ?>">
<?= $book['name']; ?> (<?= $book['releaseYear'] ?>)
</a>
</li>
<?php endforeach; ?>
</ul>
</body>
</html>
<?php
$books = [
[
'name' => 'Do Androids Dream of Electric Sheep',
'author' => 'Philip K. Dick',
'releaseYear' => 1968,
'purchaseUrl' =>'http://example.com'
],
[
'name' => 'Projekt Hail Mary',
'author' => 'Andy Weir',
'releaseYear' => 2021,
'purchaseUrl' => 'http://example.com'
],
[
'name' => 'The Martian',
'author' => 'Andy Weir',
'releaseYear' => 2011,
'purchaseUrl' => 'http://example.com'
]
];
$filteredItems = array_filter($books, function($book) {
return $book['author'] == 'Andy Weir';
});
require "index.view.php";

21
index.view.php Normal file
View file

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Demo</title>
</head>
<body>
<ul>
<?php foreach($filteredItems as $book): ?>
<li>
<a href="<?= $book['purchaseUrl']; ?>">
<?= $book['name']; ?> (<?= $book['releaseYear'] ?>)
</a>
</li>
<?php endforeach; ?>
</ul>
</body>
</html>