Giter VIP home page Giter VIP logo

Comments (2)

DominikAngerer avatar DominikAngerer commented on July 29, 2024

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.

DominikAngerer avatar DominikAngerer commented on July 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.