html - Create hreflang tags only using Liquid in Business catalyst -


i wondering if there more efficient way create hreflang tags, using liquid in bc, without need create webapp.

i tried way makes sense, doesn't work reason.

{% capture pagurl -%}{module_pageaddress}{% endcapture -%} {% if pagurl contains "http://us." -%} <link rel="alternate" href="{{ pagurl}}" hreflang="en-us" /> <link rel="alternate" href="{{ pagurl | replace: 'http://us', 'http://www' }}" hreflang="en-uk" /> <link rel="alternate" href="{{ pagurl | replace: 'http://us', 'http://au' }}" hreflang="en-au" /> <link rel="alternate" href="{{ pagurl | replace: 'http://us', 'http://eu' }}" hreflang="en" /> {% elsif pagurl contains "http://au." -%} <link rel="alternate" href="{{ pagurl}}" hreflang="en-au" /> <link rel="alternate" href="{{ pagurl | replace: 'http://au', 'http://www' }}" hreflang="en-uk" /> <link rel="alternate" href="{{ pagurl | replace: 'http://au', 'http://us' }}" hreflang="en-us" /> <link rel="alternate" href="{{ pagurl | replace: 'http://au', 'http://eu' }}" hreflang="en" /> {% elsif pagurl contains "http://eu." -%} <link rel="alternate" href="{{ pagurl}}" hreflang="en" /> <link rel="alternate" href="{{ pagurl | replace: 'http://eu', 'http://us' }}" hreflang="en-us" /> <link rel="alternate" href="{{ pagurl | replace: 'http://eu', 'http://au' }}" hreflang="en-au" /> <link rel="alternate" href="{{ pagurl | replace: 'http://eu', 'http://www' }}" hreflang="en-uk" /> {% elseif pagurl contains "http://www." -%} <link rel="alternate" href="{{ pagurl}}" hreflang="en-uk" /> <link rel="alternate" href="{{ pagurl | replace: 'http://www', 'http://us' }}" hreflang="en-us" /> <link rel="alternate" href="{{ pagurl | replace: 'http://www', 'http://au' }}" hreflang="en-au" /> <link rel="alternate" href="{{ pagurl | replace: 'http://www', 'http://eu' }}" hreflang="en" /> {% else -%} {% endif  -%} 

the weird part is, following works on same page.

{% capture pagurl -%}{module_pageaddress}{% endcapture -%} {{ pagurl}}<br> {{ pagurl | replace: 'http://www', 'http://us' }}<br> {{ pagurl | replace: 'http://www', 'http://au' }}<br> {{ pagurl | replace: 'http://www', 'http://eu' }}<br> 

and works

{{ pagurl | replace: 'http://www', 'http://us' | prepend: '<link rel="alternate" href="' | append: '" hreflang="en-us" />' }} 

the shorter code better of course.

ok daut, you're going love this! ;p

i ran similar obstacles when working on solution this issue. (i'll explain below).

as far can tell, bc has issues around rendering of liquid when comes urls , variables. don't understand ins , outs of liquid in terms of server-side processing things not appear work should in bc.

for example, if take code , strip bare essentials:

this (whether inserted <head> or <body>) doesn't work:

    {% capture pagurl -%}         {module_pageaddress}     {% endcapture -%}          <link rel="alternate" href="{{pagurl}}" hreflang="en-us"> 

it outputs <link rel="alternate" href="{{pagurl}}" hreflang="en-us">, {{pagurl}} being literal text rendered.

but work:

    {% capture pagurl -%}         {module_pageaddress}     {% endcapture -%}           {% assign test = '<link rel="alternate" href="' | append: {{pagurl}} | append: '" hreflang="en-us">' -%}      {{test}} 

compare above issues ran into.

this doesn't work:

    {module_pageaddress collection="page" template=""}     {module_siteurl collection="site" template=""}      {% assign fullurl = "http://{{site.siteurl}}/" -%}      {% if page.pageurl == {{fullurl}} -%}          // on home page      {% else -%}          // not on home page      {% endif -%} 

the problem here {{site.siteurl}} inside variable declaration. not sure issue can't handle jandle.

but work:

    {module_pageaddress collection="page" template=""}     {module_siteurl collection="site" template=""}      {% assign fullurl = 'http://' | append: {{site.siteurl}} | append: '/' -%}      {% if page.pageurl == {{fullurl}} -%}          // on home page      {% else -%}          // not on home page      {% endif -%} 

and getting example, (ironically) this works:

    {% capture pagurl -%}         {module_pageaddress}     {% endcapture -%}      <a href="{{pagurl}}">test</a> 

go figure.

i'm pretty sure bc has automatic way of grabbing head elements contained anywhere on page , re-inserting them head (even if inserted head begin with).

i wonder if causes problems in cases <link rel="alternate" href="{{pagurl}}" hreflang="en-us">. doesn't explain issue ran though.

end of day, think there still big issues bc's implementation of liquid.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -