chilldev/view-helpers-bundle

General-purpose view helpers for PHP templating engine from Chillout Development.

This package's canonical repository appears to be gone and the package has been frozen as a result.

0.1.9 2014-06-30 13:41 UTC

This package is not auto-updated.

Last update: 2019-03-01 00:08:44 UTC


README

ChillDevViewHelpersBundle is a Symfony2 bundle that brings set of useful view helpers for PHP templating engine.

Build Status Scrutinizer Quality Score Coverage Status Dependency Status SensioLabsInsight

Because not everyone uses Twig…

Installation

This bundle is provided as Composer package. To install it simply add following dependency definition to your composer.json file:

"chilldev/view-helpers-bundle": "dev-master"

Replace dev-master with different constraint if you want to use specific version.

Note: This bundle requires PHP 5.4.

Configuration

All you need to do in order to use this bundle's goods is to load it in your kernel:

<?php

use ChillDev\Bundle\ViewHelpersBundle\ChillDevViewHelpersBundle;

use Symfony\Component\HttpKernel\Kernel as BaseKernel;

class Kernel extends BaseKernel
{
    public function registerBundles()
    {
        $bundles = [
            new ChillDevViewHelpersBundle(),
        ];
    }
}

Of course there are some optional configuration options.

Usage

Major feature of this bundle is set of common (X)HTML tag helpers like <meta>, <link> etc. Here is sample usage:

In your view file:

<?php $view->extend('::layout.html.php'); ?>

<?php $view['title']->append($page->getName()); ?>
<?php $view['meta']->getMetaName('keywords')->append($page->getKeywords()); ?>
<?php $view['meta']->setMetaName('description', \strip_tags($page->getDescription())); ?>
<?php $view['meta']->setProperty('og:title', $page->getName()); ?>
<?php $view['link']->add('http://example.com/page-2-slug.html', 'next'); ?>
<?php $view['script']->add('/javascript/prototype.js'); ?>
<?php $view['xmlns']['http://www.w3.org/1999/xhtml'] = ''; ?>
<?php $view['xmlns']['http://purl.org/NET/hinclude'] = 'hx'; ?>
<?php $view['xmlns']['http://ogp.me/ns#'] = 'og'; ?>
<?php $view['xmlns']['http://ogp.me/ns/fb#'] = 'fb'; ?>

<p><?php echo $view['truncate']->truncate($text, 255); ?></p>

In your layout file:

<!DOCTYPE html>
<html<?php echo $view['xmlns']; ?>>
    <head>
        <?php echo $view['title']; ?>
        <?php echo $view['meta']; ?>
        <?php echo $view['link']; ?>
        <?php echo $view['script']; ?>
    </head>
    <body>
        <?php $view['slots']->output('_content') ?>
    </body>
</html>

For more advanced aspects see advanced usage documentation or even internals description.

Extras

There are also some extra resources included in this bundle that can be useful for your PHP-templates-based project.

KnpPaginatorBundle supports PHP templating, but lacks default template for paginator helper. You can use one from this bundle with just following one setting in your application configuration:

# KNP paginator configuration
knp_paginator:
    template:
        pagination: "ChillDevViewHelpersBundle:Pagination:sliding.html.php"

Another additional enchantment to PHP templating engine provided by this bundle is possibility to define global templating variables. This feature is available out of the box for Twig templating engine in Symfony (with TwigBundle), but there is no equivalent for native PHP templates. Now, with our bundle you can do:

chilldev_viewheleprs:
    globals:
        values:
            slogan: "The best page ever!"
        services:
            sms: "your.sms.service"

And use it directly in templates:

<h1><?php echo $slogan; ?></h1>
<p><?php echo $sms->getGatewayNumber(); ?></p>

Resources

Contributing

Do you want to help improving this project? Simply fork it and post a pull request. You can do everything on your own, you don't need to ask if you can, just do all the awesome things you want!

This project is published under MIT license.

Authors

ChillDevViewHelpersBundle is brought to you by Chillout Development.

List of contributors: