blua.blue PHP SDK

Create your own blog.

What is blua.blue?

Dubbed a “Content Enablement Platform”, blua.blue is an open source CMS with the capabilities to be used as

  • hybrid
  • headless
  • decoupled or
  • coupled CMS

In our scenario, we are using it as headless CMS and build a simple personal blog.

Preparation

When we grow, we will want to run our own installation of blua.blue. For now, registering here will be enough. In order to test our blog, let’s write a sample post. The things we want to ensure for now are

  • unchecking the “Appear in search & make public” checkbox and
  • using “WYSIWYG (HTML)” as content type ( dropdown choice when clicking “add new content”)

Once this is done, let’s jump to our IDE

Install the PHP SDK

Using composer, we install the PHP SDK for blua.blue

composer require blua-blue/blua-blue-php-sdk

and then our templating:

composer require neoan3-apps/ops

Our blog setup

Our project will consist of only two templates and one PHP file:

templates/overview.html

templates/article.html

index.php

The overview HTML template can look however you want to. For now, I will start as simple as this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>My blog</title>
</head>
<body>
    <div n-for="articles as article">
        <a href="index.php?article={%7Barticle.slug}}">{%7Barticle.name}}</a>
    </div>
</body>
</html>

Note how we use two things you might notice: n-for will iterate over articles for us while the curly braces substitute values for us just like in many other concepts you might be familiar with.

In order to better understand this, let’s look at our initial index.php

<?php

// required for Ops
define('path', __DIR__);

require path . '/vendor/autoload.php';

// use your own credentials
$userName = 'demo';
$password = 'sampleUser1';

// initiate SDK
$client = new \BluaBlue\Client($userName, $password);

// render overview.html with article list

echo \Neoan3\Apps\Ops::embraceFromFile('templates/overview.html',[
    'articles' => $client->getArticleList(0,300,$userName)
]);

We should already have output at this point. However, as indicated by the links in our template, we should probably account for the GET parameter “article” to be set or not. Let’s first create a simple article template:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{%7Bname}}</title>
</head>
<body>

<h1>{%7Bname}}</h1>
<p n-for="content as part">
    {%7Bpart.content}}
</p>
</body>
</html>

and then add the rendering option to our index.php

if(isset($_GET['article'])){
    // render article page
   $article = $client->getArticle($_GET['article']);
    echo \Neoan3\Apps\Ops::embraceFromFile('templates/article.html', $article );
}

Our complete index.php could look something like this:

<?php

// required for Ops
define('path', __DIR__);

require path . '/vendor/autoload.php';

// use your own credentials
$userName = 'demo';
$password = 'sampleUser1';

// initiate SDK
$client = new \BluaBlue\Client($userName, $password);

if(isset($_GET['article'])){
    // render article page
    echo \Neoan3\Apps\Ops::embraceFromFile('templates/article.html', $client->getArticle($_GET['article']));
} else {
    // render overview.html with article list
    echo \Neoan3\Apps\Ops::embraceFromFile('templates/overview.html',[
        'articles' => $client->getArticleList(0,300,$userName)
    ]);
}

And that’s it. You can now start designing, creating menus and improve on what we have.

neoan @neoan

321 readers
Keywords
blog php
On topic

Install PHP 7.4 on Ubuntu

Finally PHP 7.4 is out! You have read about the new features, you have followed externals, you have gathered ideas on how new capabilities will save time. Let's get it running.

Static content pages - still the fastest web-experience

Tutorial: How to utilize blua.blue to generate static content for your website.

Scaffolding REST APIs with JWT authentication

Ever had the need for your own backend while developing your web-app?

Git: globally change GitHub-remotes from git@ to https

Does your IDE or composer set remote repositories to ssh rather than https? Or are repositories you are using set up that way? You are not alone. Let's fix it once and for all!

VueJS & neoan3: a love story.

Setting up neoan3 to play nice with Vue isn't hard. Here is how the two frameworks are combined to support fast, dynamic and rapid development.

SEO strategies for blua.blue

How to get your content listed where you want it to.

MySQL: ERROR1364 fix

The painful realization of why people use containers.

How to Build an Express App in Node That Reads From a Headless CMS

A headless CMS lets you design your own front-end, sometimes your own back-end. Let's set up a small application to get us started. Beginner friendly. Approx. 20 min. to reproduce / follow along

MySQL in PHP - how to deal with databases

How I handle MYSQL database transactions in PHP

Cross publishing to dev.to

How to publish your content to dev.to from blua.blue - hopefully

How to install global npm packages without sudo on Ubuntu

Running npm on a server can be painful. Privileges are there for a reason, and so is sudo. Running npm with sudo is not the solution.

Transformer - falling in love with PHP's magic methods all over again

PHP's magic functions have been around for a long time. But there were always good reasons to avoid them. Transformer is a practical and reliable way to make use of the most common operations we program: CRUD operations.

What is composer?

Composer has become PHP's package & dependency manager. Why you should use it.