Frontend\Views

To help generating views, CodeCube uses PHP Template Inheritance plugin, as well as various custom methods.

As explained in Directory Structure, all the files necessary to generate views are stored in resources directory. There, you can store css, js, images and various asset files in resources/assets directory, layouts and class-names for various PHP tags for the views that will be automatically generated by the system in resources/xml directory, and necessary PHP view files in resources/views directory.

Defining Layouts

To define a layout, you can create a layout.php file, and use startblock() & endblock() methods to define each section for the layout like below-

<html>
<head>
<title><?php startblock('title') ?><?php endblock() ?></title>
</head>
<body>
<?php startblock('content') ?> <?php endblock() ?>
</body>
</html>

Extending a Layout

Once defined you can extend the layout file in home.php file like below-

<?php inherits(‘layout’); ?>

<?php startblock('title') ?>Home<?php endblock() ?>

<?php startblock('content') ?>This is my content!<?php endblock() ?>

Above, the inherits() method is used to call the parent view the child view is extending form.

Including other views & assets

To include other views, use the append() method like below-

append(‘front.leftbar', [‘items’ => $items]);

Above, views/front/leftbar.php file is included in the home.php file and items array is passed to it.

To include css files, use the style() method like below-

echo style('style.css');

To include js files, use the script() method like below-

echo script('script.js');

To show the title of the application, use the title() method. To show any other text other then title, pass the text as parameter-

echo title(‘My Title’);

It will show the generated title using the text along with project name given in the APP_NAME constant, like this-

My Title || Project Name

To get the source of a file uploaded in the directory defined in the upload key in config/app.php file in a view, use the asset() method like below-

echo asset(‘document.pdf’);

To show image in view, use the image() method like below-

echo image(‘my_image.jpg’);

To show an image’s thumbnail in view that was saved during upload, pass the thumbnail extension text as an argument to the image() method like below-

echo image(‘my_image.jpg’, 'alt', [], '_thumb');

The framework will automatically detect whether the image exists, if not it will use the value of placeholder key set in config/app.php instead.

To show the default icon of the website, use the icon() method like below-

echo icon('favicon.ico');