Plugin Directory

Changeset 2472625


Ignore:
Timestamp:
02/10/2021 08:15:19 PM (5 years ago)
Author:
abigegg
Message:

Update readme

File:
1 edited

Legend:

Unmodified
Added
Removed
  • hatch/trunk/readme.txt

    r2472621 r2472625  
    1111Hatch is a helper library for developers which makes it more pleasant to build websites using Timber, Advanced Custom Fields Pro and other common plugins.
    1212
    13 == Setup ==
     13== What is this thing? ==
    1414
    15 1. Install and activate the plugin.
    16 2. Go to Settings > CAF Donations and enter your charity's donation URL in the box. This normally looks like this: https://cafdonate.cafonline.org/10805
    17 3. Now you can generate donation URLs in your code using the abe_caf_get_donation_link() function! See below.
     15Hatch is a helper library for developers which makes it more pleasant to build websites using Timber, Advanced Custom Fields Pro and other common plugins.
    1816
    19 == Example usage ==
     17== A better way to use Timber ==
    2018
    21 Once you've set up the plugin and entered your charity's CAF url, you can call the `abe_caf_get_donation_link` function like so:
     19Using [Timber](https://en-gb.wordpress.org/plugins/timber-library/) we can use Twig templates to build our sites rather than PHP.
     20
     21Typically we set up a Timber context like this:
    2222
    2323`
    24 abecaf_get_donation_link( $amount, $regular );
     24$context = Timber::get_context();
     25
     26$context['post'] = Timber::get_post();
     27
     28function website_get_related_posts() {
     29    // do something fancy here
     30
     31    return [];
     32}
     33
     34$context['related_posts'] = website_get_related_posts();
     35
     36Timber::render( 'post.twig', $context );
    2537`
    2638
     39This is _fine_ but it can get a bit mucky - especially if we have complicated page templates with lots of variables.
    2740
    28 Generate the URL to make a one-off £10 donation:
     41Hatch provides a tidier way of setting up contexts for Timber and other popular libraries:
     42
    2943`
    30 abecaf_get_donation_link( 10, false );
     44// 'post' is already added by default
    3145
    32 // "https://cafdonate.cafonline.org/10742?caf_donationamount=10&caf_paymenttype=single"
     46Hatch::add_context( 'related_posts', function() {
     47    // do something fancy
     48    return [];
     49} );
     50
     51Hatch::render( 'post.twig' ); // no need to pass $context in
    3352`
    3453
    35 
    36 Generate the URL to make a recurring £25 donation:
    37 `
    38 abecaf_get_donation_link( 25, true );
    39 
    40 // "https://cafdonate.cafonline.org/10742?caf_donationamount=25&caf_paymenttype=regular"
    41 `
     54More & better documentation to come! Look in abe-hatch.php for more info
    4255
    4356== License ==
Note: See TracChangeset for help on using the changeset viewer.