Menu icon Foundation
Set Partial name as a variable

Hi,

I know it might not the way to do this, but if there is another way of doing that, please let me know too. Thank you!

 

I'm trying to insert partial into html file using panini like:

---

name: abc

---

email context...

...

{{> {{name}}}}

 

However it is not working in compiled html and show me an error message like:

Error: Parse error on line 182:

            ...spacer>{{>{{name}}}}

            ---------------------^

            Expecting 'OPEN_SEXPR', 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'OPEN'

 

 

emails;panini;partials

Hi,

I know it might not the way to do this, but if there is another way of doing that, please let me know too. Thank you!

 

I'm trying to insert partial into html file using panini like:

---

name: abc

---

email context...

...

{{> {{name}}}}

 

However it is not working in compiled html and show me an error message like:

Error: Parse error on line 182:

            ...spacer>{{>{{name}}}}

            ---------------------^

            Expecting 'OPEN_SEXPR', 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'OPEN'

 

 

Rafi Benkual about 2 years ago

I'm not aware of the ability to parse a handlebars expression inside of another. Have you seen this in other handlebars libraries?

It would help to understand what you're trying to accomplish and we can point you in the right direction.

Hao Yu about 2 years ago

Thank you Rafi.

Say I have serveral partials html file with different name that I can choose to insert into my emails.

I want to simply type in the partials names in the front matter block so that me and others don't have to scroll down in html file to change the partial names that are inserted into the emails. Is there anyway I could accomplish that?

 

Basically it looks like this:

//front matter block

---

Pname: partial1

---

//content of my email

...

{{> Pname}}

 

Antoine Fricker over 1 year ago

I might be a bit late but I will write here a solution for posterity : 

In the page [EDITED error quoted by James Donnelly]
{{> myPartial var1="myPartial2" var2="hello world" }}

In partials/myPartial.html
{{> (lookup . 'var1') }}

In partials/myPartial2.html
{{var2}}

 

James Donnelly over 1 year ago

Hi,

I'm guessing you want it use like snippets of code that get re-used?

Most editors will have some sort of snippet/partial system built in. I use Sublime for example and I can create custom snippets so I just type a short code hit tab and my code magically appears. See how to use snippets here.

You would then just amend the snippet if you need to update it. Only problem with this is if your existing templates are using a partial then you'd manually have to go in and change them all.

JD

Antoine Fricker over 1 year ago

Many roads lead to Rome...

- but to share the journey with other developpers, handlebars/panini are IMHO better shoes.

James Donnelly over 1 year ago

Antoine, in your solution all I get is "Error: The partial test could not be found"

What is your folder structure?

JD

Antoine Fricker over 1 year ago

Sorry replace the first line : 
{{> myPartial var1="myPartial2" var2="hello world" }}

I have edited the post above.