Dynamic Path for Global Partial

Hello,

The CMS doesn’t load the partial file if my code is:

{% global_partial path="../kits/"~theme.layouts.header~"/templates/header/"~theme.layouts.header~"-header.html" %}

But it will load the file if the code is

{% global_partial path="../kits/amazing/templates/header/amazing-header.html" %}

The

theme.layouts.header equals to “amazing”

Do you have any idea of using Dynamic Path for Global Partials?

Thank you very much.

Hi, @tiennguyenvan :waving_hand: Let’s see if we can get the conversation started for you. Hey, @Anton @miljkovicmisa @Jake_Lett have you solved this one, or similar problems, before?

Thank you very much! — Jaycee

Hello Jaycee,

I am using a workaround solution:

{% if theme.layouts.header == "amazing" %}
 {% global_partial path="../kits/amazing/templates/header/amazing-header.html" %} 
{% endif %}

But this is not an ideal solution because I have to add the same code everytime when I have a new header layout.

Thank you very much.

Hi!
Have you tried wrapping in {{ }}

{% global_partial path="../kits/"~{{ theme.layouts.header }}~"/templates/header/"~{{ theme.layouts.header }}~"-header.html" %}

alternatively

{% set partial_url = "../../templates/partials/" ~ module.partial ~ ".html" %}
{% global_partial path={{ partial_url }} %}

Variables are not parsed in the global_parial function. So the ‘if’ method seems to be the only solution for now.