Giter Site home page Giter Site logo

wpemerge-blade's Introduction

WP Emerge Blade

Enables the use of Blade views in WP Emerge.

Summary

Quickstart

  1. Run composer require htmlburger/wpemerge-blade in your theme directory
  2. Add \WPEmergeBlade\View\ServiceProvider to your array of providers in WP Emerge's configuration:
    \App::make()->bootstrap( [
        'providers' => [
            \WPEmergeBlade\View\ServiceProvider::class,
        ],
    ] );
  3. If you are using the WP Emerge Starter Theme you can replace your theme views with the ones inside theme/views-alternative/blade/.
  4. If you are using the WP Emerge Starter Theme you must enable the filter_core_templates configuration option in order to have .blade.php template support for WordPress core templates (index.php, single.php etc.).

Options

Default options:

[
    // Automatically replace the default view engine for WP Emerge.
    'replace_default_engine' => true,

    // Pass .php views to the default view engine.
    // replace_default_engine must be true for this to take effect.
    'proxy_php_views' => true,

    // Filter core theme templates to search for .blade.php files.
    // This is only necessary in themes.
    'filter_core_templates' => false,

    // Options passed directly to Blade.
    'options' => [
        // 'views' defaults to the main ['views'] key of the configuration.
        'views' => [get_stylesheet_directory(), get_template_directory()],
        // 'cache' defaults to the main ['cache']['path'] key of the configuration.
        'cache' => 'wp-content/uploads/wpemerge/cache/blade',
    ],
]

You can change these options by specifying a blade key in your WP Emerge config array:

\App::make()->bootstrap( [
    // ... other WP Emerge options
    'blade' => [
        // ... other WP Emerge Blade options
        'options' => [
            // ... other Blade options
            'cache' => get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'blade-cache',
        ],
    ],
] );

Extending Blade

You can use the following to extend blade with a custom directive, for example:

// \App::resolve() used for brevity's sake - use a Service Provider instead.
$blade = \App::resolve( WPEMERGEBLADE_VIEW_BLADE_VIEW_ENGINE_KEY );
$blade->compiler()->directive( 'mydirective', function( $expression ) {
    return "<?php echo 'MyDirective: ' . $expression . '!'; ?>";
} );

With this, you now have your very own custom Blade directive:

@mydirective('foobar')

More information on how you can extend Blade is available on https://laravel.com/docs/5.4/blade#extending-blade

WooCommerce

In order to render WooCommerce templates using Blade you must NOT use the .blade.php extension for WooCommerce templates as it will not detect them. Instead, use the usual .php extension for your files, for example:

  • my-theme/woocommerce.php
  • my-theme/woocommerce/single-product.php
  • my-theme/woocommerce/archive-product.php

Even though these files are .php, this extension will render them using Blade.

wpemerge-blade's People

Contributors

atanas-dev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.