Skip to content

Rjgoolsby/yii2-social-share

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

yii2-social-share

Yii2 Social Link Sharer

Built using Bootstrap Social and Font Awesome , two very cool projects ! Please keep in mind that this is a work in progress.

Install

The preferred way of installing is through composer

    composer require --prefer-dist bigpaulie/yii2-social-share "dev-master"

OR add to composer.json

    "bigpaulie/yii2-social-share": "dev-master"

Example usage :

    use bigpaulie\social\share\Share;

By default you can run the widget with no configuration parameters

    echo Share::widget();

this will produce an unordered list "ul" tag like

    <ul>
        <li><a>....</a></li>
        <li><a>....</a></li>
        <li><a>....</a></li>
    </ul>

Changing the layout of the widget

    echo Share::widget([
        'type' => 'small',
        'tag' => 'div',
        'template' => '<div>{button}</div>',
    ]);

The output of this will be something similar to :

    <div>
        <div><a> .... </a></div>
        <div><a> .... </a></div>
        <div><a> .... </a></div>
    </div>

The shared URL

By default the widget set's the URL to the current route, you can change that as needed by using the "url" property.

    echo Share::widget([
        'url' => 'http://www.domain.com',
    ]);

Or

    echo Share::widget([
        'url' => Url::to(['site/index'] , TRUE),
    ]);

Don't forget to require the helper library Url and to use the second parameter of the method for the full URL to the page.

    use yii\helpers\Url;

Attributes of main container

You can add or change attributes of the main container using the htmlOptions property. By default the main container has an id attribute similar to #w0, you can change that if you want.

    echo Share::widget([
        'htmlOptions' => [
            'id' => 'new-id',
            'class' => 'my-class',
        ],
    ]);

Widget button types

The widget provides to types of buttons small (icon only) large (icon + text) The default text for the large buttons is "Share on NETWORK", where NETWORK is the name of the social network ex : Facebook. You can change the default text by using the "text" property of the widget.

    echo Share::widget([
        'text' => 'Click to share on {network}',
    ]);

Networks

Currently the widget provides 4 buttons Facebook Google Plus Twitter Linkedin

About

Yii2 Social Link Sharer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 89.1%
  • CSS 8.3%
  • JavaScript 2.6%