1. Go to this page and download the library: Download jahuty/snippets-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jahuty / snippets-php example snippets
$jahuty = new \Jahuty\Client('YOUR_API_KEY');
$render = $jahuty->snippets->render(YOUR_SNIPPET_ID);
$jahuty = new \Jahuty\Client('YOUR_API_KEY');
$renders = $jahuty->snippets->allRenders('YOUR_TAG');
foreach ($renders as $render) {
echo $render;
}
// Prefer the latest content for all renders.
$jahuty = new \Jahuty\Client('YOUR_API_KEY', ['prefer_latest' => true]);
// Use the default published content for all renders.
$jahuty = new \Jahuty\Client('YOUR_API_KEY');
// And, render the latest content for this one.
$render = $jahuty->snippets->render(YOUR_SNIPPET_ID, ['prefer_latest' => true]);
$jahuty = new \Jahuty\Client('YOUR_API_KEY');
// This call sends a synchronous API request; caches the result in memory; and,
// returns the resulting render.
$render1 = $jahuty->snippets->render(YOUR_SNIPPET_ID);
// This call skips sending an API request and uses the cached render instead.
$render2 = $jahuty->snippets->render(YOUR_SNIPPET_ID);
$jahuty = new \Jahuty\Client('YOUR_API_KEY', ['cache' => CACHE_INSTANCE]);
// Cache all renders for sixty seconds.
$jahuty = new \Jahuty\Client('YOUR_API_KEY', [
'cache' => $cache,
'ttl' => 60
]);
// Use the caching implementation's TTL for all renders.
$jahuty = new \Jahuty\Client('YOUR_API_KEY', ['cache' => $cache]);
// But, cache this render for 60 seconds.
$render = $jahuty->snippets->render(1, [
'ttl' => 60
]);
$jahuty = new \Jahuty\Client('YOUR_API_KEY');
// This call sends a network request, caches each render, and returns the
// collection.
$jahuty->snippets->allRenders('YOUR_TAG');
// ... later in your application
// If this snippet exists in the previously rendered collection, the cached
// render will be used.
$render = $jahuty->snippets->render(YOUR_SNIPPET_ID);
// Disable all caching
$jahuty1 = new \Jahuty\Client('YOUR_API_KEY', ['ttl' => 0]);
// Disable caching for this render
$jahuty2 = new \Jahuty\Client('YOUR_API_KEY');
$jahuty2->snippets->render(1, ['ttl' => 0]);
try {
$jahuty = new \Jahuty\Client('YOUR_API_KEY');
$render = $jahuty->snippets->render(YOUR_SNIPPET_ID);
} catch (\Jahuty\Exception\Error $e) {
// The API returned something besides 2xx status code. Access the problem
// object for more information.
$problem = $e->getProblem();
echo $problem->getStatus(); // returns status code
echo $problem->getType(); // returns URL to more information
echo $problem->getDetail(); // returns description of error
}
javascript
{
"jahuty-php": "^5.4"
}
}
html+php
$jahuty = new \Jahuty\Client('YOUR_API_KEY');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.