Comments (2)
Which version are you currently using?
I can't seem to find that line on Line 85 of our Client.php: https://github.com/storyblok/php-client/blob/master/src/Storyblok/Client.php#L85
Here is an example on how to use the current version:
$client->getStoryBySlug('home');
$response = $client->getBody(); // contains the data of your story.
from storyblok-php-client.
Found the example you've used - sorry for not having that updated!
Need to run it on my side to test it (currently on mobile) but attached already an updated version with the code above.
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
body {
font-family: sans-serif;
}
.teaser,
.column {
font-size: 2rem;
text-align: center;
line-height: 3;
background: #ebeff2;
border-radius: 10px;
margin: 10px 5px;
}
.grid {
display: flex;
}
.column {
flex: 1;
}
</style>
</head>
<body>
<?php
require 'vendor/autoload.php';
// Defines templates
// This is usually handled by the template engine using seperate files.
class Components
{
function page($blok)
{
$content = '';
foreach ($this->_get($blok, 'body') as $innerblok) {
$content .= $this->{$innerblok['component']}($innerblok);
}
return $content;
}
function teaser($blok)
{
return $this->_get($blok, '_editable') . '<div class="teaser">' . $this->_get($blok, 'headline') . '</div>';
}
function grid($blok) {
$content = '<div class="grid">';
foreach ($this->_get($blok, 'columns') as $innerblok) {
$content .= $this->{$innerblok['component']}($innerblok);
}
$content .= '</div>';
return $content;
}
function feature($blok) {
return $this->_get($blok, '_editable') . '<div class="column teaser">' . $this->_get($blok, 'name') . '</div>';
}
function _get($blok, $key) {
return isset($blok[$key]) ? $blok[$key] : '';
}
}
// Simple rendering engine
// Replace that with twig or other template engine of your preference.
function renderBlocks($data) {
$components = new Components();
$blok = $data['story']['content'];
echo $components->{$blok['component']}($blok);
}
// Handles catch all route
$path = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
$slug = empty($path) ? 'home' : $_SERVER['REQUEST_URI'];
$client = new \Storyblok\Client('jdS0oLvdm3Hoj8OILqOcRQtt');
$client->getStoryBySlug($slug);
$response = $client->getBody();
renderBlocks($response);
?>
<script src="//app.storyblok.com/f/storyblok-latest.js?t=jdS0oLvdm3Hoj8OILqOcRQtt"></script>
</body>
</html>
from storyblok-php-client.
Related Issues (20)
- Language is not respected if a single story should be fetched
- Infinite recursion in V2, when _storyblok_published is set HOT 1
- The getLinks method takes options which are not keyed in the cache
- Huge memory consumption in v2 HOT 3
- Storyblok can't be used with PHP 8.1 and Symfony v6 (or rather `symfony/cache` >=6.0) HOT 3
- Please create a new tag with the last changes from march HOT 2
- Language is not taken into consideration when caching / checking the cache HOT 1
- Why is this repository so neglected? Is contribution still appreciated? HOT 3
- Compatibility with PHP 8.2 HOT 1
- Add "default_lifetime" cache option for start using defaultLifetime param for caching
- Feature: Introducing Static Code Analysis, PHPStan and refactor at least for level 2 HOT 2
- Resolve Relations: sorting issue HOT 1
- Feature: increase PHPstan at level 3
- Improve exception handling HOT 1
- Support more cache drivers or allow users to create their own HOT 1
- Client->getStories not respecting release HOT 1
- Upgrade for PHP cs fixer HOT 1
- v2 breaks support of PHP<8 due to symphony dependency HOT 3
- Make level of relation resolving overwritable
- Support symfony/cache 7.0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from storyblok-php-client.