PHP Helper functions for building sites using Base 5.
Add the following to your composer.json file:
"repositories": [
{
"type": "git",
"url": "git@github.com:RootStudio/BaseLayout-PHP-Helpers.git"
}
],
"require": {
"rootstudio/base-php-helpers": "^2.1",
}The v2.x version of the library requires PHP 7 or higher. For versions below this change the require statement to:
"require": {
"rootstudio/base-php-helpers": "^1.2",
}If you need to modify the public and layout directories you can set the following constants early in your code:
define('BASE_PUBLIC_DIR', 'public');
define('BASE_LAYOUT_DIR', 'layouts');This package includes PHP functions that streamline building sites using the BaseLayout 5 boilerplate.
base_asset()andbase_public_path()functions for asset management- API compatibility with
perch_layout_*functions - Additional PHP libraries for working with Strings and Dates.
The mix helper should be used to call in static assets compiled with Laravel Mix. For example:
<?phprequire'vendor/autoload.php'?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Base NG</title>
<link rel="stylesheet" href="<?phpechobase_asset('assets/css/global.css'); ?>">
</head>
<body>
<!-- Page Content... -->
<script src="<?phpechobase_asset('assets/js/manifest.js'); ?>"></script>
<script src="<?phpechobase_asset('assets/js/vendor.js'); ?>"></script>
<script src="<?phpechobase_asset('assets/js/app.js'); ?>"></script>
</body>
</html>Whether a static site or one that will be integrated with Perch, it is good to seperate certain re-usable files into partials:
<?phpbase_layout('global/header', ['class' => 'home']); ?>The function accepts 3 parameters:
- The path to the file (relative to the
layoutsdirectory) - An array of variables to passed through
- Optionally return rather than echo the template
Inside the layout file variables can be echoed or returned using
<?phpbase_layout_var('class'); ?>Variables can also be checked with:
<?php base_layout_has('class'); ?>
The Faker library allows you to generate random content for a wide variety of patterns. For a full list see the documention.
$faker = base_faker_factory();
echo$faker->email;If you only need a single use you can shorthand the above to:
echobase_faker_factory()->email;The fully qualified domain name can be returned using base_http_host(). The function will automatically add the correct protocol if SSL is enabled:
<link rel="icon" sizes="152x152" href="<?phpechobase_http_host(); ?>/images/meta/touch-icon.png">Perch
Migrating a static site to Perch is simply a matter of replacing base_ with perch_ on each of the above functions. This is deliberate to reduce the time spent converting files to use Perch's template system.
Included are useful libraries for handling strings and dates:
Date and time manipulations made easy:
useCarbon\Carbon;
Carbon::now()->addMonths(2)->format('d/m/Y');View Documentation: http://carbon.nesbot.com/docs/
Advanced string manipulation and utilities. Makes checking for strings and modifying format very simple:
useStringy\StringyasStringy;
if(Stringy::create('Tom Bradley ordered 6 Products')->contains('Tom Bradley')) {
echo'Alert Lydia!';
}View Documentation: https://github.com/danielstjules/Stringy
Generates mock content for for a wide variety of patterns including names, addresses, emails, urls and even images.
$faker = Faker\Factory::create();
echo$faker->sentence;View Documentation: https://github.com/fzaninotto/Faker