CMS Development

tiennguyenvan
Participant

Dynamic Path for Global Partial

SOLVE

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.
0 Upvotes
1 Accepted solution
kevinfilteau
Solution
Participant

Dynamic Path for Global Partial

SOLVE

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

View solution in original post

0 Upvotes
4 Replies 4
kevinfilteau
Solution
Participant

Dynamic Path for Global Partial

SOLVE

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

0 Upvotes
Jaycee_Lewis
Community Manager
Community Manager

Dynamic Path for Global Partial

SOLVE

Hi, @tiennguyenvan 👋 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

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

tiennguyenvan
Participant

Dynamic Path for Global Partial

SOLVE

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.

0 Upvotes
republiken
Participant

Dynamic Path for Global Partial

SOLVE

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 }} %}