Skip to content

Instantly share code, notes, and snippets.

@medienbaecker
Created May 6, 2020 11:23
Show Gist options
  • Save medienbaecker/c027d4d5c4c7c80a4a1412a1f2bb5f92 to your computer and use it in GitHub Desktop.
Save medienbaecker/c027d4d5c4c7c80a4a1412a1f2bb5f92 to your computer and use it in GitHub Desktop.
Programmatically add template to images
<?php
return [
'routes' => [
[
'pattern' => 'imagetemplates',
'action' => function () {
$result = '';
foreach(site()->index() as $page) {
$result .= '<h2>' . $page->title() . '</h2>';
foreach($page->files() as $file) {
try {
$file->update([
'template' => 'default',
]);
$result .= '<h3>' . $file->filename() . ' ✅</h3>';
}
catch(Exception $e) {
$result .= '<h3>' . $file->filename() . ' ❎</h3>';
}
}
}
return $result;
}
]
]
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment