handlebars.jsassemblestatic-site

Use a variable to pick which partial to use


I'm looking to load a partial based on a variable that is in the front matter data of the content page that i have. I've been able to get handlebars to pass back the correct variable name from in side the page but it will not then process the resulting string as a request to a partial:

<div class="sub-column">{{> (rhs1) }}</div>

this then just outputs the content of the variable rather than then going to find the partial it is referring to. I have also tried is using {{{ }}} but this has not helped.

Is this possible or am I going about this the wrong way?


Solution

  • I had to use a helper function to return the partial:

    fs.readFileSync('src/partials/'+content+'.html', 'utf8');
    

    this then allowed the system to recognise that we wanted to point to the partial.