Skip to content

Instantly share code, notes, and snippets.

@ocorreiododiogo
Last active December 21, 2015 15:39
Show Gist options
  • Save ocorreiododiogo/6328103 to your computer and use it in GitHub Desktop.
Save ocorreiododiogo/6328103 to your computer and use it in GitHub Desktop.
Quick interface to batch delete template in ProcessWire
<?php
if ($input->post->submit) {
foreach ($input->post as $t) {
// proceed only if the input is an integer different from 0
if (!(int)$t) return;
$t = $templates->get($t);
$templates->delete($t);
$name = $t->name;
// delete the fieldgroup associated with this template. more info in the next post
$fg = $fieldgroups->get($name);
$fieldgroups->delete($fg);
// verify that the template is not there and print the confirmation
if (!$templates->get($t)) echo "<p>template {$name} was deleted.</p>";
}
} else {
// print the form
echo "<form method='post'>";
echo "<ul>";
foreach ($templates as $t) {
// name of the template and number of pages it uses
echo "<li>" . $t->name . " (" . $t->getNumPages() . " pages)";
// include checkbox if the template is not used by pages, and set it's id as value
if (!$t->getNumPages()) echo " <input type='checkbox' value='{$t->id}' name='{$t->name}'>";
echo "</li>";
}
echo "</ul>";
echo "<input type='submit' value='delete these' name='submit'>";
echo "</form>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment