silverbackis/bw-base-bundle

该软件包已被弃用且不再维护。作者建议使用 silverbackis/common-js-bundle 软件包。

一个用于创建英国网站的 Symfony 3 Bundle。扩展了 Sonata SEO Bundle,并提供配置链接标签(用于图标)和一些常用 JavaScript SDK 包含功能。

安装: 48

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

公开问题: 0

类型:symfony-bundle

dev-master 2017-11-23 14:14 UTC

This package is auto-updated.

Last update: 2022-05-15 11:18:29 UTC


README

此 Bundle 扩展了非常受欢迎的 Sonata SEO Bundle,并提供了以下附加功能:

  • 配置链接标签
  • 启用 JavaScript SDK,无需额外扩展,并具有一些额外的配置选项。
  • 将适当的元标签和链接标签转换为完整 URL,并尊重配置文件中设置的 base_urls 选项。
  • 能够定义具有相同名称的多个元标签(用于多个 og:image 标签)。

安装

您可以使用 composer 安装此 Bundle。

composer require silverbackis/bw-base-bundle

然后启用 两者 Sonata SEO 和 BW Base Bundle。

// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    // ...

    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Sonata\SeoBundle\SonataSeoBundle(),
            new BW\BaseBundle\BWBaseBundle(),
        );

        // ...
    }
}

有一个 twig 模板,您可以从它扩展模板,该模板将插入来自 Sonata SEO 和 BW Base 的所有默认 Twig 函数。

{% extends '@BWBase/base.html.twig' %}

配置

默认设置了 2 个参数,可以覆盖(或如果您不想使用,则可以不使用)。

favicon_base: bundles/app/images/favicon
opengraph_base: bundles/app/images/opengraph

以下是此 Bundle 的完整配置示例。

bw_base:
  page:
    metas:
      name:
        twitter:site:       '@silverbackis'
        twitter:image:      '%opengraph_base%opengraph_image1.png'
        # auto = same as Sonata SEO title tag
        twitter:title:      'auto'
        # auto = same as meta description (from either Sonata SEO or BW Base)
        twitter:description: 'auto'
      property:
        # auto = same as Sonata SEO title tag
        - { property: "og:title", content: "auto" }
        # auto = same as meta description (from either Sonata SEO or BW Base)
        - { property: "og:description", content: "auto" }
        # auto = get URL from the current request
        - { property: "og:url", content: "auto" }
        - { property: "og:image", content: "%opengraph_base%opengraph_image1.png" }
        - { property: "og:image:width", content: "500" }
        - { property: "og:image:height", content: "500" }
        - { property: "og:image", content: "%opengraph_base%opengraph_image2.png" }
    links:
      rel:
        apple-touch-icon-precomposed:
          - { sizes: 57x57, href: '%favicon_base%apple-touch-icon-57x57.png' }
        icon:
          - { type: image/png, sizes: 196x196, href: '%favicon_base%favicon-196x196.png' }
    js_sdk:
      google_analytics:
        enabled: true
        id: UA-12345678-01
        domain: www.yourdomain.com
      woopra:
        enabled: true
        domain: www.yourdomain.com
      facebook_pixel:
        enabled: true
        id: pixelID
      facebook:
        enabled: true
        app_id: 1234567890
        xfbml: true
        version: 'v2.8'
        language: en_GB
        login_status_check: false
        debug: false
      twitter: true

Twig 函数

当您调用以下 twig 函数时,BW Base Bundle 中定义的元标签将与 Sonata SEO Bundle 中定义的元标签合并。

{{ bwbase_meta_tags() }}

还有更多可用的 Twig 函数。

{# Outputs the title without the title tag for easy block overriding #}
{{ bwbase_title() }}

{# Outputs the link tags #}
{{ bwbase_link_tags() }}

{# You can omit the parameter to output all the sdks. Otherwise you can specify or use 'head' or 'body' for each sdks preferred location #}
{{ bwbase_sdks_html('head') }}

{# You can also just return the raw arrays of the data when testing #}
{{ dump(bwbase_links()) }}
{{ dump(bwbase_sdks()) }}
{{ dump(bwbase_metas()) }}

BW Base 服务

您可以使用别名 bw.base.page 访问 BW Base 服务。

以下方法可用:

  • setMetas(array $metadatas)
  • addMeta($type, $name, $content, array $extras = array())
  • hasMeta($type, $name)
  • getMeta($type, $name)
  • removeMeta($type, $name)
  • removeMetaByKey($type, $key)
  • setSDKs(array $sdks)
  • getSDKs($bodyPart=false)
  • hasSDK($name)
  • getSDK($name)
  • enableSDK($name)
  • disableSDK($name)
  • setLinks(array $linkdatas)
  • getLinks()
  • hasLink($type, $name)
  • addLink($type, $name, $content)
  • removeLink($type, $name)
  • getUrl($url)

例如,您可能只想在特定页面上使用 Twitter SDK,您可以通过以下方式从控制器启用它:$this->container->get('bw.base.page')->enableSDK('twitter')