Skip to content

Commit

Permalink
Use proper paths, fix the filter that inlines the template
Browse files Browse the repository at this point in the history
... by not removing it before it runs, but checking the handle instead
  • Loading branch information
kraftner committed Nov 3, 2016
1 parent 5f22d1a commit 18f3e39
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Models/UnderscoreTemplateEnqueuer.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,23 @@ public function enqueue($template_name)

$filter = function ($script_tag_markup = '', $handle = '') use ($template_name) {

if( $handle !== "tmpl-{$template_name}" ){
return $script_tag_markup;
}

return $this->makeTemplateInline($script_tag_markup, $handle, $template_name);
};

add_filter('script_loader_tag', $filter, 20, 2);

wp_enqueue_script(
"tmpl-{$template_name}",
$this->url . $template_name . '.tmpl',
$this->templateUrl($template_name),
[],
@filemtime($path) ?: null,
true
);

remove_filter('script_loader_tag', $filter, 20);

return true;

}
Expand All @@ -92,9 +94,17 @@ public function enqueue($template_name)
*/
private function templatePath($template)
{
return $this->path . $template . '.tmpl';
return $this->path . 'assets/templates/' . $template . '.tmpl';
}

/**
* @param $template
* @return string
*/
private function templateUrl($template){
return $this->url. 'assets/templates/' . $template . '.tmpl';
}

/**
* @param $template_path
* @return string
Expand Down

0 comments on commit 18f3e39

Please sign in to comment.