Giter Club home page Giter Club logo

starratingbundle's Introduction

StarRatingBundle

Star Rating Bundle for Symfony 2. Requires Jquery and Font Awesome.

Sample Output

alt tag

Installation

Step 1: Download the StarRatingBundle

Using Composer

Add the following to the "require" section of your composer.json file:

    "blackknight467/star-rating-bundle": "1.*"

Step 2: Enable the bundle

Enable the bundle in the kernel:

<?php
// app/appKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new blackknight467\StarRatingBundle\StarRatingBundle(),
    );
}

Step 3: Add the css

Add the css in your page head

  <link rel="stylesheet" type="text/css" href="{{ asset('bundles/starrating/css/rating.css') }}" />

or

	{% stylesheets
      'bundles/starrating/css/rating.css'
      filter="cssrewrite" %}
      <link href="{{ asset_url }}" rel="stylesheet" type="text/css" />
    {% endstylesheets %}

Step 4: Add the js

Add the javascript to your page head

    <!-- make sure that jquery is included --!>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
	{% javascripts
      '@StarRatingBundle/Resources/public/js/rating.js' %}
      <script src="{{ asset_url }}"></script>
    {% endjavascripts %}

Usage

###In a Form

<?php
    // ...
    $builder->add('rating', 'rating', array(
    	'label' => 'Rating'
    ));
    // ...

or for a custom rating scale:

<?php
    // ...
    $builder->add('rating', 'rating', array(
    	//...
    	'stars' => 4,
    	//...
    ));
    // ...

###Display in a twig template using the rating filter

    // ...
    {{ someInteger|rating }}
    // ...

or if you are not using a 5 star scale

{{ someInteger|rating(4) }}

if you want to use the font awesome icon sizes

{{ someInteger|rating(5, "fa-3x") }}

If you want the smallest size use "fa-norm" (in font awesome, this would be the same as not providing an size class); providing no size argument sets the font size to 25px which is somewhere in between "fa-lg" and "fa-2x". To customize the size, feel free to override the css.

License

This bundle is under the MIT license. See the complete license in the bundle: LICENSE

starratingbundle's People

Contributors

blackknight467 avatar retosteffen avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.