c975l/sharebuttons-bundle

提供不同视图下的分享按钮,并提供URL分享功能。

v4.6 2024-09-15 16:35 UTC

README

ShareButtonsBundle 执行以下操作

  • 定义按钮,可以在不同的工具上分享网页。

此包依赖于 BootstrapFontawesome 的使用。

ShareButtonsBundle 专用网页.

ShareButtonsBundle API 文档.

包安装

步骤 1:下载 Bundle

使用 Composer 安装库

    composer require c975L/sharebuttons-bundle

步骤 2:启用路由

然后,通过将它们添加到项目的 /config/routes.yaml 文件中启用路由

c975_l_share_buttons:
    resource: "@c975LShareButtonsBundle/Controller/"
    type:     annotation
    prefix: /
    #Multilingual website use the following
    #prefix: /{_locale}
    #defaults:   { _locale: '%locale%' }
    #requirements:
    #    _locale: en|fr|es

步骤 3:与您的网站集成

强烈建议使用 覆盖第三方 Bundle 模板功能 以完全集成到您的网站中。

为此,只需在您的应用程序中创建以下结构 app/Resources/c975LExceptionCheckerBundle/views/,然后复制其中的 layout.html.twig 文件,以覆盖现有的 Bundle 文件,然后应用您需要的更改,例如语言等。

layout.html.twig 中,它将主要包含扩展布局和定义特定变量,例如

{% extends 'layout.html.twig' %}

{# Defines specific variables #}
{% set title = 'ShareButtons' %}

{% block content %}
    {% block sharebuttons_content %}
    {% endblock %}
{% endblock %}

步骤 4:使用资源

要使用样式和 JavaScript,您必须从 public/css/public/js/ 中包含它们

<link rel="stylesheet" href="bundles/c975lsite/css/animations.min.css">
<script src="bundles/c975lsharebuttons/js/functions.min.js"></script>

{# or  using c975L/IncludeLibrary #}
{{ inc_lib(absolute_url(asset('bundles/c975lsharebuttons/css/styles.min.css')), 'local') }}
{{ inc_lib(absolute_url(asset('bundles/c975lsharebuttons/js/functions.min.js')), 'local') }}

步骤 5:定义配置

您需要定义需要访问数据的角色,以及是否要保存分享的统计信息。您可以通过使用 sharebuttons_config 路由或在您的 /config/config_bundles.yaml 中直接执行此操作。在这种情况下,请不要忘记清除缓存。选项在 /Resources/config/bundle.yaml 文件中描述。

使用方法

ShareButtonsBundle 使用 Fontawesome 作为图标,其 svg 已包含在包中,以避免需要链接到 fontawesome css/js。

ShareButtonsBundle 很容易使用。您只需在您的 Twig 模板中添加以下代码,该模板使用提供的 Twig 扩展

{{ sharebuttons(['SHARE1', 'SHARE2', 'SHARE3', etc.], 'STYLE[distinct|ellipse|circle|toolbar](default distinct)', 'ALIGNMENT[left|center|right](default center)', DISPLAY_ICON[true|false](default true), DISPLAY_TEXT[true|false](default false), 'URL') }}

{# If you only need "main" shares you can also use the 'main' keyword as in the following #}
{{ sharebuttons('main', 'STYLE[distinct|ellipse|circle|toolbar](default distinct)', 'ALIGNMENT[left|center|right](default center)', DISPLAY_ICON[true|false](default true), DISPLAY_TEXT[true|false](default false), 'URL') }}

{# The simpliest use is the following #}
{{ sharebuttons('main', 'STYLE[distinct|ellipse|circle|toolbar](default distinct)') }}

使用路由 sharebuttons_dashboard(URL:"/sharebuttons/dashboard")访问仪表板。

可用网络

您可以在上面解释的 Twig 扩展中使用以下名称的任何名称,以对应相应的网络

  • facebook
  • twitter
  • linkedin
  • pinterest
  • email
  • blogger
  • buffer
  • delicious
  • evernote
  • reddit
  • skype
  • stumbleupon
  • tumblr
  • whatsapp
  • wordpress

如果这个项目 帮助您减少开发时间,您可以通过顶部按钮赞助我 :)