{if file_exists("templates/$template/includes/common/overwrites/seo.tpl")}
    {include file="{$template}/includes/common/overwrites/seo.tpl"}  
{else}
    <title>{if isset($pageSeo['title'][$language]) && !empty($pageSeo['title'][$language]) && isset($pageSeo['enabled']) && $pageSeo['enabled']}{$pageSeo['title'][$language]}{elseif $kbarticle.title}{$kbarticle.title}{elseif $templatefile == "viewinvoice" || $templatefile == "viewquote" || $templatefile == "clientareahome" || $templatefile == "viewticket"}{$pagetitle}{elseif $templatefile == "products"}{$groupname}{else}{$displayTitle}{/if}{if $templatefile == "knowledgebasecat" && $tag} - {$tag} {/if}{if $templatefile == "knowledgebasecat" && $catname} - {$catname}{/if}{if $templatefile == "announcements" && $view} - {$view}{/if} - {$companyname}</title>
    {if $templatefile == "knowledgebasearticle" || $templatefile == "viewannouncement" || $templatefile == "knowledgebasecat"}
        <meta name="description" content="{if $templatefile == "viewannouncement"}{$summary|replace:'"':''|strip:" "|truncate:155:"..."}{elseif $templatefile == "knowledgebasearticle"}{$kbarticle.text|strip_tags|replace:'"':''|strip:" "|truncate:155:"..."}{elseif $templatefile == "knowledgebasecat"}{$catname|strip_tags|replace:'"':''|strip:" "|truncate:155:"..."}{/if}">
    {elseif $templatefile == "products"}
        {if $productGroup.tagline}
            <meta name="description" content="{$productGroup.tagline|replace:'"':''|truncate:155:"..."}">
        {/if}
        {foreach from=$productgroups item=foo}
            {if $foo.gid == $gid}
                {assign var=productSlug value=$foo.slug}
            {/if}
        {/foreach}
    {elseif $siteSeoDesc}
        {if $templatefile == "store/sitebuilder/index"}
            <meta name="description" content="{$rslang->trans('sitebuilder.banner.title')|replace:'"':''|truncate:155:"..."}">
        {else}
            <meta name="description" content="{lang key=$siteSeoDesc|replace:'"':''|truncate:155:"..."}">
        {/if}              
    {/if}
    {if isset($pageSeo['enabled']) && $pageSeo['enabled']}
        {if isset($pageSeo['description'][$language]) && !empty($pageSeo['description'][$language])}<meta name="description" content="{$pageSeo['description'][$language]}">{/if}
        <meta name="robots" content="{if $pageSeo['robots'] == 0}noindex, nofollow{else}index, follow{/if}">
        <meta property="og:type" content="{if $templatefile == 'homepage'}website{else}article{/if}">
        <meta property="og:title" content="{if isset($pageSeo['title'][$language]) && !empty($pageSeo['title'][$language])}{$pageSeo['title'][$language]}{else}{$displayTitle}{/if} - {$companyname}">
        {if isset($pageSeo['description'][$language]) && !empty($pageSeo['description'][$language])}<meta property="og:description" content="{$pageSeo['description'][$language]}">{/if}
        {if isset($pageSeo['image'])}<meta property="og:image" content="{$systemurl}templates/{$template}/assets/img/page-manager/{$pageSeo['image']}">{/if}
        <meta property="og:url" content="{$systemurl}{$smarty.server.REQUEST_URI|ltrim:'/'}">
        <meta name="twitter:title" content="{if isset($pageSeo['title'][$language]) && !empty($pageSeo['title'][$language])}{$pageSeo['title'][$language]}{else}{$displayTitle}{/if} - {$companyname}">
        {if isset($pageSeo['description'][$language]) && !empty($pageSeo['description'][$language])}<meta name="twitter:description" content="{$pageSeo['description'][$language]}">{/if}
        {if isset($pageSeo['image'])}<meta name="twitter:image" content="{$systemurl}templates/{$template}/assets/img/page-manager/{$pageSeo['image']}">{/if}
    {/if}
    {if $currentUrl == '/' || $currentUrl == '/ '}    
        {if $seoHost|substr:-2 eq '/ '}
            {assign var=seoHostCanonical value=$seoHost|replace:'/ ' : ''}
        {elseif $seoHost|substr:-1 eq '/'}
            {assign var=seoHostCanonical value=$seoHost|replace:'/' : ''}
        {/if}
    {else}
        {assign var=seoHostCanonical value=$seoHost}
    {/if}
    {if $defaultLanguage eq $language}
        <link rel="canonical" href="{$seoHostCanonical}{if $currentUrl|substr:0:1 eq '/'}{$currentUrl|substr:1|replace:"?currency={$WHMCSCurrency.id}":""|replace:"&currency={$WHMCSCurrency.id}":""|replace:"?language={$language}":""|replace:"&language={$language}":""}{else}{$currentUrl|replace:"?currency={$WHMCSCurrency.id}":""|replace:"&currency={$WHMCSCurrency.id}":""|replace:"?language={$language}":""|replace:"&language={$language}":""}{/if}">
    {else}
        <link rel="canonical" href="{$seoHostCanonical}{if $currentUrl|substr:0:1 eq '/'}{$currentUrl|substr:1|replace:"?currency={$WHMCSCurrency.id}":""|replace:"&currency={$WHMCSCurrency.id}":""}{else}{$currentUrl|replace:"?currency={$WHMCSCurrency.id}":""|replace:"&currency={$WHMCSCurrency.id}":""}{/if}">
    {/if}
    {if $RSThemes.addonSettings.enable_hreflang_links == "displayed"}
        {if $currentUrl|substr:0:1 eq '/'}
            {assign var=changedCurrentUrl value=$currentUrl|substr:1|replace:"?currency={$WHMCSCurrency.id}":""|replace:"&currency={$WHMCSCurrency.id}":""|replace:"?language={$language}":""|replace:"&language={$language}":""}
        {else}
            {assign var=changedCurrentUrl value=$currentUrl|replace:"?currency={$WHMCSCurrency.id}":""|replace:"&currency={$WHMCSCurrency.id}":""|replace:"?language={$language}":""|replace:"&language={$language}":""}
        {/if}
        {if $changedCurrentUrl|strstr:"?"}
            {$divChar = "&amp;"}
        {else}
            {$divChar = "?"}
        {/if}
        {assign var=localeCode value='/'|cat:$activeLocale.languageCode|replace:' ':''}
        {assign var=fullDefaultUrl value=$seoHost|cat:$changedCurrentUrl}
        {if $fullDefaultUrl|substr:-4 eq 'ptbr' || $fullDefaultUrl|strstr:'/ptbr'}
            <link rel="alternate" hreflang="x-default" href="{$fullDefaultUrl|replace:'/ptbr' : ''}">
        {elseif $fullDefaultUrl|substr:-2 eq '/ '}
            <link rel="alternate" hreflang="x-default" href="{$fullDefaultUrl|replace:'/ ' : ''}">
        {elseif $fullDefaultUrl|substr:-1 eq '/'}
            <link rel="alternate" hreflang="x-default" href="{$fullDefaultUrl|replace:'/' : ''}">
        {else}
            <link rel="alternate" hreflang="x-default" href="{$fullDefaultUrl|replace:$localeCode : ''}">
        {/if}
        {if $currentPageLangs && !empty($currentPageLangs)}
            {foreach from=$locales item=language}
                {if ($currentPageLangs[$language.language]|default:'') eq '' && $seoHost|substr:-1 eq '/'}
                    {assign var=seoHostSecured value=$seoHost|substr:0:-1}
                {else}
                    {assign var=seoHostSecured value=$seoHost}
                {/if}
                {if $language.languageCode === 'pt'}
                    <link rel="alternate" hreflang="{$language.locale|replace:"_":"-"}" href="{$seoHostSecured}{$currentPageLangs[$language.language]}">
                {else}
                    <link rel="alternate" hreflang="{$language.languageCode|replace:"_":"-"}" href="{$seoHostSecured}{$currentPageLangs[$language.language]}">
                {/if}
            {/foreach}
        {else}
            {foreach from=$locales item=language}
                {if $language.language == $defaultLanguage && $seoHost|substr:-1 eq '/' && ($changedCurrentUrl == '' || $changedCurrentUrl == ' ')}
                    {assign var=seoHostSecured value=$seoHost|substr:0:-1}
                {else}
                    {assign var=seoHostSecured value=$seoHost}
                {/if}
                {if $language.languageCode === 'pt'}
                    <link rel="alternate" hreflang="{$language.locale|replace:"_":"-"}" href="{$seoHostSecured}{$changedCurrentUrl}{if $language.language != $defaultLanguage}{$divChar}language={$language.language}{/if}">
                {else}
                    <link rel="alternate" hreflang="{$language.languageCode|replace:"_":"-"}" href="{$seoHostSecured}{$changedCurrentUrl}{if $language.language != $defaultLanguage}{$divChar}language={$language.language}{/if}">
                {/if}
            {/foreach}
        {/if}
    {/if}
{/if}