Download the PHP package devanych/view-renderer without Composer

On this page you can find all versions of the php package devanych/view-renderer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package view-renderer

Simple View Renderer

License Latest Stable Version Total Downloads GitHub Build Status GitHub Static Analysis Status Scrutinizer Code Coverage Scrutinizer Code Quality

A small and easy-to-use PHP library designed for rendering native PHP views.

Highlights:

A guide with a detailed description in Russian language is available here.

Installation

This package requires PHP version 7.4 or later.

Usage

The simplest example of rendering:

The render() method takes as its first argument the path to the view file, which must be relative to the directory passed to the constructor when the object was created. The second argument passes an array of parameters (name => value) that will be converted to variables inside the view.

in the view:

The view file can be with or without an extension, if the file extension is not specified, .php will be substituted by default. The default extension can be changed by passing it to the constructor as the second argument.

Within layouts and views, a renderer instance is available at $this.

Blocks

The block(), beginBlock(), and endBlock() methods allow you to create content blocks in your view. The content of blocks is saved for use anywhere in the view, as well as in any parent layout. The method renderBlock() renders the stored content of the block.

Layout code:

View code:

Rendering result:

Blocks can't be nested, but you can render one block inside another.

Note that content is a reserved block name. it renders the content of the view and child layouts. If you try to create a block named content, the \RuntimeExceptionexception is thrown.

When calling the renderBlock() method with the name of a nonexistent block, the renderBlock() method returns an empty string, so no additional methods are needed to check the existence of the block. The second argument in renderBlock() can pass the default value, which will be substituted if the block with the specified name does not exist.

Layouts

Layouts are a special type of representations that are very convenient to use for rendering repetitive parts (header, footer, sidebar, etc.). This package allows you to build layout chains with unlimited nesting. Layout inheritance is set in the file of the view or child layout by the layout() method.

Parent layout code (layouts/main):

Child layout code (layouts/columns):

View code (site/page):

Rendering the view:

Rendering result:

If you just need to render the child layout file from the parent layout, you can use the render() method.

Rendering result:

Extensions

The extension functionality allows you to add your own functions and use them inside layouts and views. To add a function, you need to create your own class that implements the Devanych\View\Extension\ExtensionInterface interface. The interface contains only one method that returns an array whose keys are the names of added functions, and the values can be any possible variants of the callable type.

This package contains a single extension Devanych\View\Extension\AssetExtension, which simplifies the connection of assets (scripts, styles, fonts, etc.) and adds a timestamp to the file. To add an extension, use the addExtension() method.

Global parameters

Using the addGlobal() method, you can add global parameters that will be available in all views and layouts.

Adding a variable with the same name again will cause a \RuntimeException, but you can change the value of the global variable for a specific view by passing a parameter with the same name when rendering the view, or simply assigning it in the view itself.

Escaping

To prevent the output of potentially dangerous HTML code, the renderer contains the esc() method, which escapes special characters, converts them to the corresponding HTML entities.

This method is for convenience, but you can also use the original htmlspecialchars() function, as all existing PHP functions are available in views and layouts.


All versions of view-renderer with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package devanych/view-renderer contains the following files

Loading the files please wait ....