astina/social-links-bundle

该包已被弃用且不再维护。未建议替代包。

使用 SocialLinks 生成社交媒体分享链接的 Symfony 扩展包。

安装次数: 47,063

依赖者: 0

建议者: 0

安全: 0

星级: 11

关注者: 21

分支: 9

类型:symfony-bundle

2.3.0 2017-10-02 05:31 UTC

This package is not auto-updated.

Last update: 2022-07-15 10:49:50 UTC


README

AstinaSocialLinksBundle 实际上是围绕 oscarotero/social-links 的包装。其主要目的是根据给定的提供者生成社交链接。

目前支持提供者。

安装

步骤 1: 添加到 composer.json

"require" :  {
    // ...
    "astina/social-links-bundle":"dev-master",
}

步骤 2: 启用扩展包

在内核中启用扩展包

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Astina\Bundle\SocialLinksBundle\AstinaSocialLinksBundle(),
    );
}

使用方法

本扩展包的主要功能是为给定的提供者和 URL 生成社交链接。它可以用作 twig 扩展,如下例所示。

基本用法

{{ social_link('facebook') }}

扩展用法

{{ social_link('facebook', 'http://www.astina.ch', {'text': 'Custom text', attributes: {'class': 'custom-share', 'target': '_self'} }, 'Custom link text') }}

此示例将返回一个看起来像的 HTML 响应。

<a href="https://#/sharer.php?s=100&amp;p%5Burl%5D=http%3A%2F%2Fwww.astina.ch" class="custom-share" target="_self"></a>

辅助函数接受三个参数 - provider(字符串),url(字符串),options(多维数组)和 link text(字符串)。您可以在那里添加尽可能多的自定义属性。

选项和默认值

'title'   => null
'text'    => null
'options' => array('attributes' => array('target' => '_blank'))
'linkText => null

模板扩展

还可以通过在 app/Resources/AstinaSocialLinksBundle/views/SocialLinks 中添加 socialLink.html.twig 模板来扩展社交链接模板。

运行测试

bin/phpunit