Giter Club home page Giter Club logo

templateengineblade's Introduction

TemplateEngineBlade

ProcessWire module to add Laravel's Blade templating engine to ProcessWire, enforcing MVC and separation of concerns.

Inspired by the wonderful TemplateEngineFactory module. Check it out to get more information about the motivations that led me to build this module.

Requirements

  • Composer
  • PHP >= 5.6.0
  • ProcessWire 3

Installation

Install the module like any other ProcessWire module. Download the files and place them into the TemplateEngineBlade folder inside site/modules.

Check out the following guide for more information: http://modules.processwire.com/install-uninstall/.

Next you should install the dependencies. Run the following command from the module's folder:

composer install

Configuration

  • Path to templates Path to folder where you want to store your Blade template files.
  • API variable This is the variable you can use in the controllers (aka ProcessWire templates) to access the template of the current page
  • Template files suffix The suffix of the template files, default is blade.php.
  • Import ProcessWire API variables in Blade templates If checked, any API variable is accessible inside the Smarty templates, for example {{ $page }} refers to the current page.

Features

All Blade's features are supported:

  • Template inheritance
  • Sections
  • Includes
  • Control structures

Under the hood this module uses Philo's Laravel-Blade package.

Usage

The module uses template files under /site/templates/ as controllers that do the logic, delegating the output/markup to a corresponding view file. The default convention is the same of the TemplateEngineFactory module: the view file has the same name as the controller (aka ProcessWire template). If no template file is found, the factory assumes that the controller does not output markup over the template engine. In this case, everything works as normal.

The API variable is an instance of Illuminate\View\Factory so you can use all the methods provided by the class. For example, provided that view is the name of your API variable configured for the module, you can use:

$view->share('foo', 'bar');

to add a variable to the environment.

You can also decide to render different files based on some conditions, for example:

// In controller gallery.php

$gallery = $pages->find('...');

$view->share('gallery', $gallery);

if($input->urlSegment1 == 'grid')
{
    return $view->make('gallery.grid', ['title' => 'Display gallery as a grid']);
}
elseif($input->urlSegment1 == 'list')
{
    return $view->make('gallery.list', ['title' => 'Display gallery as a list']);
}

// in every other case it renders the gallery.blade.php view file

Note the dot-notation to access files inside a subfolder.

templateengineblade's People

Contributors

mauricius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

templateengineblade's Issues

help with template files

Hello and thank you for this module, very useful if you want to use the blade templates power...

I was trying your module and I run into this problem.
I do not fully understand how it works but for the situation below I am getting an error
Error: Uncaught ArgumentCountError: Too few arguments to function TemplateEngineBlade\TemplateEngineBlade::render(), 0 passed in F:\server_adi_2\istoriazilei.ro\site\site\modules\TemplateEngineBlade\TemplateEngineBlade.module on line 223 and exactly 1 expected in F:\server_adi_2\istoriazilei.ro\site\site\modules\TemplateEngineBlade\TemplateEngineBlade.module:245

In templates I have the home.php template, in templates/views I have home.blade.php template.
home.php content is <?php print $view->make('home'); ?> but this is not the problem, I am getting the same error even if this file is empty.

The problem is with code from hook hookRender. If I comment the hook like $this->addHookAfter('Page::render', $this, 'hookRender'); from the init function, the page is showed and it's fine.

I really do not understand what should happen when a processwire template has a blade template with the same name, how you should handle this...
Considering your example. it should handle blade template with the same name as processwire template automatically...

// In controller gallery.php

.....

$gallery = $pages->find('...');

$view->share('gallery', $gallery);

if($input->urlSegment1 == 'grid')

return $view->make('gallery.grid', ['title' => 'Display gallery as a grid']);

elseif($input->urlSegment1 == 'list')

return $view->make('gallery.list', ['title' => 'Display gallery as a list']);

.....

// in every other case it renders the gallery.blade.php view file

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.