Created
May 6, 2020 11:23
-
-
Save medienbaecker/c027d4d5c4c7c80a4a1412a1f2bb5f92 to your computer and use it in GitHub Desktop.
Programmatically add template to images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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