dxw / iguana-theme
Installs: 62 545
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 16
Forks: 0
Open Issues: 2
Requires
- php: ^7.4||^8.1
- dxw/iguana: ^1.1
Requires (Dev)
- 10up/wp_mock: ^0.4.2
- dxw/php-cs-fixer-config: ^2.1
- mikey179/vfsstream: ^1.6
- phpunit/phpunit: ^9.0
README
Helper functions and template layouts for iguana-based themes.
\Dxw\Iguana\Theme\Helpers
Helper functions.
Installation
Add the following to app/di.php
:
$registrar->addInstance(new \Dxw\Iguana\Theme\Helpers());
Usage
Your classes can declare helper functions:
<?php
namespace Dxw\MyTheme;
class MyClass implements \Dxw\Iguana\Registerable
{
private $helpers;
public function __construct(\Dxw\Iguana\Theme\Helpers $helpers)
{
$this->helpers = $helpers;
}
public function register()
{
$this->helpers->registerFunction('myFunc', [$this, 'myFunc']);
}
public function myFunc($a)
{
echo esc_html($a + 1);
}
}
To call this function from a template:
<?php h()->myFunc(4) ?>
Using h()
means that you only need to pollute the global namespace with one function. And h()
is a lot shorter than typing out the full namespace.
All you need to do is pass the Helpers
instance to your class during instantiation. Example:
$registrar->addInstance(new \Dxw\MyTheme\MyClass(
$registrar->getInstance(\Dxw\Iguana\Theme\Helpers::class)
));
\Dxw\Iguana\Theme\Layout
and \Dxw\Iguana\Theme\LayoutRegister
Layout templates.
Installation
Add the following to app/di.php
:
$registrar->addInstance(new \Dxw\Iguana\Theme\Helpers());
$registrar->addInstance(new \Dxw\Iguana\Theme\LayoutRegister(
$registrar->getInstance(\Dxw\Iguana\Theme\Helpers::class)
));
Usage
Add something like this to layouts/main.php
(within your theme directory):
<!doctype html>
<html>
<head>
...
</head>
<body>
<?php h()->w_requested_template() ?>
</body>
</html>
And remove the calls to get_header()
/get_footer()
from all your templates.