Changeset 2472625
- Timestamp:
- 02/10/2021 08:15:19 PM (5 years ago)
- File:
-
- 1 edited
-
hatch/trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
hatch/trunk/readme.txt
r2472621 r2472625 11 11 Hatch is a helper library for developers which makes it more pleasant to build websites using Timber, Advanced Custom Fields Pro and other common plugins. 12 12 13 == Setup==13 == What is this thing? == 14 14 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. 15 Hatch is a helper library for developers which makes it more pleasant to build websites using Timber, Advanced Custom Fields Pro and other common plugins. 18 16 19 == Example usage==17 == A better way to use Timber == 20 18 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: 19 Using [Timber](https://en-gb.wordpress.org/plugins/timber-library/) we can use Twig templates to build our sites rather than PHP. 20 21 Typically we set up a Timber context like this: 22 22 23 23 ` 24 abecaf_get_donation_link( $amount, $regular ); 24 $context = Timber::get_context(); 25 26 $context['post'] = Timber::get_post(); 27 28 function website_get_related_posts() { 29 // do something fancy here 30 31 return []; 32 } 33 34 $context['related_posts'] = website_get_related_posts(); 35 36 Timber::render( 'post.twig', $context ); 25 37 ` 26 38 39 This is _fine_ but it can get a bit mucky - especially if we have complicated page templates with lots of variables. 27 40 28 Generate the URL to make a one-off £10 donation: 41 Hatch provides a tidier way of setting up contexts for Timber and other popular libraries: 42 29 43 ` 30 abecaf_get_donation_link( 10, false ); 44 // 'post' is already added by default 31 45 32 // "https://cafdonate.cafonline.org/10742?caf_donationamount=10&caf_paymenttype=single" 46 Hatch::add_context( 'related_posts', function() { 47 // do something fancy 48 return []; 49 } ); 50 51 Hatch::render( 'post.twig' ); // no need to pass $context in 33 52 ` 34 53 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 ` 54 More & better documentation to come! Look in abe-hatch.php for more info 42 55 43 56 == License ==
Note: See TracChangeset
for help on using the changeset viewer.