2017 © Pedro Peláez
 

library mvc

An helper component for MVC in Wordpress

image

wbf/mvc

An helper component for MVC in Wordpress

  • Thursday, May 25, 2017
  • by Waga Dev
  • Repository
  • 3 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

MVC

MVC paradigm for Wordpress templates., (*1)

This component provide the ability to effectively split code from templates in Wordpress., (*2)

Usage of HTMLView

HTMLView is the default view type provided by component. You can use is to display HTML templates., (*3)

  • Create a new instance of HTMLView:
$v = new \WBF\components\mvc\HTMLView("path/to/template.php");
  • Assign some vars to the template and display it
$vars = [
    'title' => "Hello World"
];
$v->display();
  • In template.php you can:
<?php echo $title; ?>

The View has some really interesting features:, (*4)

  • You can provide a path relative to the current theme or relative to a plugin. The template file will be enqueued in a template hierarchy array, so you can override the template file by placing a new template with the same name/path in a child theme. If the path is relative to a plugin, any similiar template found in child theme or in parent theme will override the original template. php //If you are in a twentysixteen child called "foobar"... $v = new \WBF\components\mvc\HTMLView("path/to/template.php"); /* Will looking for (in order): /wp-content/themes/foobar/path/to/template.php /wp-content/themes/twentysixteen/path/to/template.php */
  • You can easily cache the $vars array to boost performances. The same task can be tedious with a simple require.
  • You can easily implement some other templating systems by extending View.

Use dashboard page wrapper

$v = new \WBF\components\mvc\HTMLView("path/to/template.php");
$v->for_dashboars()->display([
    'page_title' => "My awesome title",
    'my_name' => "Maya"
]);

With template.php:, (*5)

Hello <?php echo $my_name ?>!

Will display:, (*6)

<div class="wrap">
    <h1>My awesome title</h1>
    Hello Maya!
</div>

Use custom page wrapper

$v = new \WBF\components\mvc\HTMLView("path/to/template.php");
$v->display([
    'page_title' => "My awesome title",
    'wrapper_class' => "my_wrap",
    'wrapper_el' => "section"
    'title_wrapper' => "<span>%s</span>"
    'my_name' => "Maya"
]);

With template.php:, (*7)

Hello <?php echo $my_name ?>!

Will display:, (*8)

<section class="my_wrap">
    <span>My awesome title</span>
    Hello Maya!
</section>

The Versions

25/05 2017

dev-master

9999999-dev http://www.waga.it

An helper component for MVC in Wordpress

  Sources   Download

GPL-2.0+

The Requires