Skip to content

Instantly share code, notes, and snippets.

@AugustMiller
Last active April 4, 2018 12:15
Show Gist options
  • Save AugustMiller/f0e99dc76062852587e8 to your computer and use it in GitHub Desktop.
Save AugustMiller/f0e99dc76062852587e8 to your computer and use it in GitHub Desktop.
Kirby snippet fallback function
<?php function try_snippet($try, $data = [], $return = false) {
$snippets = kirby::instance()->roots()->snippets();
foreach ( $try as $snippet ) {
$file = $snippets . DS . $snippet . '.php';
if ( f::exists($file) ) {
return tpl::load($file, $data, $return);
} else {
continue;
}
}
}
@yoanmalie
Copy link

@AugustMiller Where did you put this code ? In which file ? Thanks

@raphaelsaunier
Copy link

@yoanmalie I generally put these site-specific helpers in site/plugins/, where they're picked up automatically by Kirby.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment