2017 © Pedro Peláez
 

library component-templating

Advanced Custom Fields helper for WordPress

image

flexpress/component-templating

Advanced Custom Fields helper for WordPress

  • Thursday, August 21, 2014
  • by timperry
  • Repository
  • 0 Watchers
  • 0 Stars
  • 69 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

FlexPress templating component

Install via Pimple

The templating components a class and a interface: - Functions, which hooks into the Twig environment and adds the functions you add to it. - FunctionInterface, an interface that you must adheer to., (*1)

Lets create the pimple config for the functions and a Hello World function class that we will create later:, (*2)

$pimple['helloWorldFunction'] = function() {
  return new HelloWorld();
};

$pimple['templatingFunctions'] = function ($c) {
    return new TemplatingFunctions($c['objectStorage'], array(
      $c['helloWorldFunction']
    ));
};

Note the objectStorage is the SPLObjectStorage class., (*3)

Creating a concreate class that implments the interface

You need to implement the FunctionsInterface and create a class that can be added to the Functions service, so lets create a simple hello world one now:, (*4)

class HelloWorld implements FunctionInterface {

  public function getFunctionName() {
    return "helloWorld";
  }

  public function getFunctionBody() {
    echo "Hello world";
  }

}

As you can see the getFunctionName() gets the name of the function and the getFunctionBody() is what is outputted when you call the function., (*5)

Before we use this in the a twig view we need to get the templatingFunctions service to register the functions, simply create an instance of it and it will setup the hooks, so just call the pimple config:, (*6)

$pimple['templatingFunctions'];

Finally you would use this in a view like this, (*7)

{{ helloWorld() }}

Public methods - Functions

  • getTwig() - Used by a hook to add in all the functions

Public methods - FunctionInterface

  • getFunctionName() - Returns the name of the function.
  • getFunctionBody() - This method is called when you use the function in a view, can do anything you want.

Builtin functions

As well as creating your own functions there are a few built in functions:, (*8)

  • BodyClasses - Used to output the classes for the tag.
  • ThePageTitle - Used to output the page title inside the tags.

The Versions

21/08 2014

dev-master

9999999-dev

Advanced Custom Fields helper for WordPress

  Sources   Download

21/08 2014

v1.0.1

1.0.1.0

Advanced Custom Fields helper for WordPress

  Sources   Download

13/08 2014

v1.0.0

1.0.0.0

Advanced Custom Fields helper for WordPress

  Sources   Download