Could anybody help me to explain me this part of Hubl Code and what means this ~ sign?

{% set operator = “&” if “?” in page_meta.canonical_url else “&” %}

if I understand correctly it means that apply & if there is a ? in page… else use & ??

Looks like this means the same right?

Also I see often this sign:

~

What does this sign mean exactly?

Please see the full code below:

{## 
 # Share Icons
 # 
 # This module display icons to share current content or 
 # custom link in networks.
 # 
 # @Field type Boolean {module.isActive} Shows or hides the module. Accept 'true' or 'false'. Default 'true'.
 # @Field type Text {module.title} Module main title.
 # @Field type Link {module.link} Field thats enable to customize the url to share.
 # @Field type Group {module.networks} Group of networks options.
 # {
 # @Field type Boolean {module.facebook} Enable or disable share in Facebook. Default 'true'.
 # @Field type Boolean {module.twitter} Enable or disable share in Twitter. Default 'true'.
 # @Field type Boolean {module.linkedin} Enable or disable share in LinkedIn. Default 'true'.
 # @Field type Boolean {module.pinterest} Enable or disable share in Pinterest. Default 'true'.
 # @Field type Boolean {module.whatsapp} Enable or disable share in Whatsapp. Default 'true'.
 # @Field type Boolean {module.email} Enable or disable share in Email. Default 'true'.
 # }
 #}

{# Define the module internal name #}
{% set module_slug = "share-content" %}

{# Macro to define each network url #}
{% macro networkUrl( network ) %}

 {# Variables #}
 {% set custom_url = module.link.url.href %}
 {% set canonical_url = page_meta.canonical_url %}
 {% set operator = "&" if "?" in page_meta.canonical_url else "&" %}
 {% set page_title = page_meta.name %}

 {# Define the final link to share #}
 {% if custom_url %}
 {% set url = custom_url ~ operator ~ "utm_medium=social&utm_source="|safe ~ network %}
 {% else %}
 {% set url = canonical_url ~ operator ~ "utm_medium=social&utm_source="|safe ~ network %}
 {% endif %}

 {# Define the final url to each network #}
 {% if network == 'facebook' %}
 {{ "http://www.facebook.com/share.php?u=" ~ url }}
 {% elif network == 'twitter' %}
 {{ "https://twitter.com/ubiqum" ~ url ~ "&url=" ~ url ~ "&source=tweetbutton&text=" ~ page_meta.html_title|urlencode ~ ": " }}
 {% elif network == 'linkedin' %}
 {{ "https://www.linkedin.com/school/ubiqum-academy/mycompany/" ~ url }}
 {% elif network == 'pinterest' %}
 {{ "http://pinterest.com/pin/create/button/?url=" ~ url ~ "&media=" ~ pinterest_media }}
 {% elif network == 'whatsapp' %}
 {{ "whatsapp://send?text=" ~ page_meta.html_title|urlencode ~ ": " ~ url }}
 {% elif network == 'email' %}
 {{ "mailto:?subject=" ~ page_title|urlencode ~ "&body=" ~ page_meta.html_title|urlencode ~ ": " ~ url }}
 {% endif %}

{% endmacro %}

{# Macro to define the network list item #}
{% macro networkItemList( network ) %}
 {% if module.networks[network] %}
 <li class="{{ module_slug }}-item {{ module_slug }}-item-{{ network }}">
 <a href="{{ networkUrl( network ) }}" title="Share in {{ network|capitalize }}" onclick="return false;">
 <img src="{{ module_asset_url("icon-" ~ network ~ ".png") }}" alt="{{ network|capitalize }} icon">
 </a>
 </li>
 {% endif %}
{% endmacro %}

{# The module code starts here #}
{% if module.isActive %}
 <div id="{{ module_slug }}" class="module">
 <div class="{{ module_slug }}-wrapper {{ module.title_position }}-title">

 {# Header #}
 {% if module.title %}
 <div class="{{ module_slug }}-header">
 <h3>{{ module.title }}</h3>
 </div>
 {% endif %}

 {# Listing #}
 <ul class="{{ module_slug }}-listing">
 {{ networkItemList( 'facebook' ) }}
 {{ networkItemList( 'twitter' ) }}
 {{ networkItemList( 'linkedin' ) }}
 {{ networkItemList( 'pinterest' ) }}
 {{ networkItemList( 'whatsapp' ) }}
 {{ networkItemList( 'email' ) }}
 </ul>

 </div>
 </div>
{% endif %}

Thanks for your help already!

Hello @KBergmeijer!
The expression {% set operator = “&” if “?” in page_meta.canonical_url else “&” %} doesn’t make much sense to me since the operator variable will be & in both cases.

Regarding the symbol ~, it is used to concatenate strings.

{% set variable = "world!" %}{% set text = "Hello " ~ variable %}{{text}} //This will print "Hello world!"

Hi @KBergmeijer ,

This whole code is for social sharing , Its used in Blog post pages in hubspot for sharing the blog post on social platform.
And this tilde ~ sign is concatenate the links parts in this code
{% set operator = “&” if “?” in page_meta.canonical_url else “&” %}
This code is for canonical page url
for understanding what is canonial url -
A canonical URL is the URL of the page that Google thinks is most representative from a set of duplicate pages on your site. For example, if you have URLs for the same page ( Example Domain and example.com/dresses/1234 ), Google chooses one as canonical.
For more Knowing about canonical url you can visit here How to Specify a Canonical with rel="canonical" and Other Methods | Google Search Central  |  Documentation  |  Google for Developers

Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.
Thanks and Regards.