Skip to content

Commit

Permalink
readme update, autoload filters
Browse files Browse the repository at this point in the history
  • Loading branch information
mejta committed Mar 21, 2019
1 parent 2fd131a commit 1590520
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
],
"minimum-stability": "stable",
"autoload": {
"psr-4": {"NetteLatteEngine\\": "src/"}
"psr-4": {"NetteLatteEngine\\": "src/"},
"files": ["wp-latte.php"]
},
"require": {
"latte/latte": "^2.5"
Expand Down
25 changes: 18 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@ PHP: 5.6.0+
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

## Usage
## Instalation with Composer

1. Go to `wp-content/mu-plugins` folder and require wp-latte with `composer require mejta/wp-latte` command.
1. Don't forget to load composer dependencies in your loader (e.g. `wp-content/mu-plugins/load.php`):

```php
<?php // wp-content/mu-plugins/load.php
require WPMU_PLUGIN_DIR . '/vendor/autoload.php';
```

## Instalation with Git

1. Go to `wp-content/mu-plugins` folder and clone the repository with `git clone git@github.com:mejta/wp-latte.git` command.
1. Go to plugin folder with `cd wp-latte`
Expand All @@ -21,6 +31,8 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.html
require WPMU_PLUGIN_DIR . '/wp-latte/wp-latte.php';
```

## Usage

After plugin activation, you can use Nette Latte templates in your theme. Just use `.latte` file extension instead of `.php`. Template files with `.php` extension will continue to work, but that templates will have lower priority in template resolution.

There are limitations with `header.php` and `footer.php`. You should use instead `{php wp_head()}` and `{php wp_footer()}` macro inside layout file. If you need to use header.php and footer.php file (e.g. for WooCommerce plugin), leave that files blank.
Expand All @@ -30,15 +42,14 @@ If you want to have a fallback for a case when the plugin is not activated, add
You can also define your custom filters and macros. Use the following code in your `functions.php` file.

```php
<?php // wp-content/themes/my-theme/functions.php
use NetteLatteEngine\NetteLatteEngine;

if (class_exists('NetteLatteEngine\NetteLatteEngine')) {
// https://latte.nette.org/en/guide#toc-user-defined-macros
NetteLatteEngine::addMacro('test', $start_php_code, $end_php_code);
// https://latte.nette.org/en/guide#toc-user-defined-macros
NetteLatteEngine::addMacro('test', $start_php_code, $end_php_code);

// https://latte.nette.org/en/guide#toc-custom-filters
NetteLatteEngine::addFilter('test', $callback_function);
}
// https://latte.nette.org/en/guide#toc-custom-filters
NetteLatteEngine::addFilter('test', $callback_function);
```

If you want define custom post template, create a template file in theme root directory and put the comment block at the begining of the file like this:
Expand Down
17 changes: 1 addition & 16 deletions wp-latte.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,2 @@
<?php
/*
Plugin Name: Nette Latte Engine
Description: Nette Latte template engine support for WordPress.
Author: Daniel Mejta
Version: 1.0.0
Author URI: https://www.mejta.net
*/

if (!function_exists('add_action')) {
exit;
}

if(!class_exists('NetteLatteEngine\NetteLatteEngine')) {
require __DIR__ . '/vendor/autoload.php';
NetteLatteEngine\NetteLatteEngine::initialize();
}
NetteLatteEngine\NetteLatteEngine::initialize();

0 comments on commit 1590520

Please sign in to comment.