Skip to content

Instantly share code, notes, and snippets.

@nunof07

nunof07/setup.php

Created Apr 12, 2019
Embed
What would you like to do?
Automatically register component aliases in Sage.
<?php
/**
* Register component aliases.
*/
add_action('after_setup_theme', function () {
$template_directory = "views/components/";
$path = get_stylesheet_directory() . '/' . $template_directory;
if (!is_dir($path)) {
return;
}
$dir = new \DirectoryIterator(\locate_template($template_directory));
foreach ($dir as $fileinfo) {
if ($fileinfo->isDot()) {
continue;
}
$slug = str_replace('.blade.php', '', $fileinfo->getFilename());
$alias = preg_replace('/[^\da-z]/i', '', $slug);
sage('blade')->compiler()->component("components.$slug", $alias);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment