question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Render partial via config variable

See original GitHub issue

I was hoping to use some config data (YAML) to dynamically specify another partial to render/include.

Handlebars’ documentation suggests this is possible, like so:

{{> (lookup . 'myVariable') }}

See: http://handlebarsjs.com/partials.html

This however results in The partial could not be found.

I also found #195 and #239 regarding this.

I tried using the ‘workaround’ specified here but no luck: https://github.com/frctl/fractal/issues/239#issue-223851818

Is this possible?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
dkhuntrodscommented, Jul 21, 2017

Hi @iamkeir

This is definitely possible:

  1. Define the template name in your config data (note the double backslash, this escapes the component name and so prevents Fractal trying to inject context data):
context: {
  inputTemplate: '\\@input-pair'
}
  1. Render your dynamic partial in your .hbs file:
{{>(lookup . 'inputTemplate') }}

Let me know if this helps.

2reactions
thomasaullcommented, Jan 7, 2020

@flepp, @LeBenLeBen Another way to do it is to set your childTemplate like \\@card--zoom and render it like

{% render childTemplate, childContext %}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to render a partial by passing a local variable for ...
In Rails 5.2.2 I am trying to render a partial using a local variable as the collection, but when running a test to...
Read more >
ActionView::PartialRenderer - Rails API
You can specify a partial to be rendered between elements via the :spacer_template option. The following example will render advertiser/_ad_divider.html.erb ...
Read more >
Partial views in ASP.NET Core | Microsoft Learn
Discover how to use partial views to break up large markup files and reduce the duplication of common markup across web pages in...
Read more >
Partials - Frontend - Winter CMS Documentation
Introduction; Rendering partials; Passing variables to partials ... The partial configuration section can also contain component definitions ...
Read more >
Let's Use Rails Partials To Render Art from Magic: the Gathering!
Using render partial : within views and other partials; Passing variables to partials with locals: Rendering partials repeatedly by iterating ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found