This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
huna
I created a Plugin to extend my local project's Twig in /plugins/huna/wpasset
<?php namespace Huna\WpAsset;
use System\Classes\PluginBase;
class Plugin extends PluginBase
{
public $elevated = true;
private $manifest;
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails() {
return [
'name' => 'wp assets',
'description' => 'wp assets',
'author' => 'huna',
];
}
/**
* Register markup filters and functions to be used in Twig
*
* @return array
*/
public function registerMarkupTags() {
return [
'filters' => [
'wpasset' => [$this, 'getWpAsset'],
],
];
}
public function getWpAsset($assetname) {
$this->manifest = file_get_contents('manifest.json');
$this->manifest = json_decode($this->manifest, true);
if (!isset($this->manifest[$assetname])) return $assetname;
return $this->manifest[$assetname]['src'];
}
}
To use that in markup, in default.htm
description = "Default layout"
==
<!DOCTYPE html>
<html>
<head>
{% partial 'site/meta' %}
</head>
<body>
<section id="layout-content">
{% page %}
</section>
<script src="{{ 'main.js'|wpasset }}"></script>
</body>
</html>
When I access the homepage, I get this error
We're sorry, but an unhandled error occurred. Please see the details below.
Unknown "wpasset" filter.
What am I missing so that the filter is recognized and I can use that syntax in my templates?
1-1 of 1