diff --git a/pl_attach-library.function.php b/pl_attach-library.function.php
index 3e02ee6..b2bd3b3 100644
--- a/pl_attach-library.function.php
+++ b/pl_attach-library.function.php
@@ -14,6 +14,17 @@
$yamlFile = glob('*.libraries.yml');
$yamlOutput = Yaml::parseFile($yamlFile[0]);
+ $directoryPath = explode('/', dirname(__FILE__));
+
+ $rootPathString = '';
+ // If the themes directory is in the path (Drupal).
+ if (in_array('themes', $directoryPath)) {
+ $rootPathLocation = array_search('themes', $directoryPath);
+ $themePathOffset = -1 * (count($directoryPath) - array_search('components', $directoryPath));
+ $rootPath = array_slice($directoryPath, $rootPathLocation, $themePathOffset, true);
+ $rootPathString = implode('/', $rootPath) . '/';
+ }
+
// For each item in .libraries.yml file.
foreach($yamlOutput as $key => $value) {
@@ -22,7 +33,7 @@
$files = $yamlOutput[$key]['js'];
// For each file, create an async script to insert to the Twig component.
foreach($files as $key => $jsPath) {
- $scriptString = '';
+ $scriptString = '';
$stringLoader = \PatternLab\Template::getStringLoader();
$output = $stringLoader->render(array("string" => $scriptString, "data" => []));
return $output;