{#
# Project: www.betten-abc.de
# Company: arboro GmbH
# Created by: Daniel Geike
# Created on: 01.09.22
# Description:
#}
{% block page_product_detail_button_share %}
{# get meta title from meta title block and trim white-space #}
{% set metaTitle = block("layout_head_title_inner", "@Storefront/storefront/page/product-detail/meta.html.twig")|trim %}
{# get meta description and trim white-space #}
{% set metaDescription = page.metaInformation.metaDescription|trim|replace({
"\t": ""
}) %}
{# get page URL #}
{% set pageURL = seoUrl('frontend.detail.page', {
productId: page.product.id
}) %}
{# get media ID of first media item #}
{% set imageURL = page.product.media.first.media.url %}
{% set shareOptions = {
name: metaTitle,
description: metaDescription,
url: pageURL,
imageUrl: imageURL
} %}
<button type="button" class="btn product-detail-button product-detail-button-share" data-share="true" data-share-options="{{ shareOptions|json_encode }}">
{% sw_icon "share" %}
{{ "detail.buttons.share.label"|trans }}
</button>
{% block page_product_detail_button_share_facebook %}
{% set locale = app.request.attributes.get("_locale")|replace({
"-": "_"
}) %}
<!-- Load Facebook SDK for JavaScript -->
<div id="fb-root"></div>
<script>( function( d, s, id ) {
var js, fjs = d.getElementsByTagName( s )[ 0 ];
if ( d.getElementById( id ) ) return;
js = d.createElement( s );
js.id = id;
js.src = 'https://connect.facebook.net/{{ locale }}/sdk.js#xfbml=1&version=v3.0';
fjs.parentNode.insertBefore( js, fjs );
}( document, 'script', 'facebook-jssdk' ) );
</script>
<!-- Your share button code -->
<div class="fb-share-button"
data-href="{{ pageURL }}"
data-layout="button"
>
</div>
{% endblock %}
{% endblock %}