Fractal: `default.context` not available in (twig) preview templates

Created on 25 May 2021  路  9Comments  路  Source: frctl/fractal

global.context data is not made available to (twig) preview templates.

This used to work with version 1.1.x of fractal.

Steps to reproduce the issue

  1. set a global context
fractal.components.set('default.context', {
    manifest: {
        'main.js': 'main.h65dd5.js',
    }
})
  1. use the context in a preview template
{{ dump(manifest['main.js']) }}
  1. output is undefined. It should be main.h65dd5.js.

Reproduces how often:

100%

Reduced test case

https://gist.github.com/therealpecus/a9ba99ddff7b0ebecf1cd39871c3e68d

Context

bug

All 9 comments

I found a workaround, but the issue remains:

using _config.components.default.context.manifest['main.js'] works.

Thanks for the issue! Weird stuff. I took a project of mine, updated the Fractal dependencies to latest and your example works like a charm. In this repo, however, it did not. Looked around a bit - this seems to be dependent on the file structure. If you put the preview template directly in the components directory, it acts as the default preview for all components and it totally disregards what you've set as the default preview in the config. However, if you move the preview template to a subdirectory, it works.

image

Are you sure it worked differently in an earlier version? Could you provide a repository with older versions to demonstrate that?

Are you sure it worked differently in an earlier version? Could you provide a repository with older versions to demonstrate that?

I double checked and I was mistaken: it never worked.

Thanks for reviewing the issue so quickly! The preview template position in the directory structure seems to be the culprit, and it might be enough to update the documentation to mention it. Currently, the docs say:

Preview layouts are just another component, and so must reside in your component directory. Like any other components, preview layouts can be hidden by prefixing their name with an underscore if you don't want them to show up in listings or navigation.

For example, we could create a preview layout called _preview.hbs in the root our components directory:

source

The other place where it might be useful to add a note is when documenting default.context:

default.context

Global context data that will be made available to all components when rendering previews, unless overridden in a collection or component configuration file.

I'd still categorize this as a bug / unexpected behavior, it's just that since it's not a regression and has worked this way since 2016, it gets a little bit lower priority.

I've got the same problem.

Help out with testing / reviewing the fix in the PR linked above! If noone tells us it's better with the fix, it'll never get merged/released.

Or, if the fix does not solve the issues, more info is needed to investigate further.

Help out with testing / reviewing the fix in the PR linked above! If noone tells us it's better with the fix, it'll never get merged/released.

Or, if the fix does not solve the issues, more info is needed to investigate further.

I had missed it! I'll review the PR

@mihkeleidast I reviewed the PR by testing the same case that prompted this bug and I can confirm it is fixed. I do not have write permissions on the repo but LGTM and should be merged

Was this page helpful?
0 / 5 - 0 ratings

Related issues

julmot picture julmot  路  3Comments

alexrussell picture alexrussell  路  7Comments

Maybach91 picture Maybach91  路  5Comments

allmarkedup picture allmarkedup  路  7Comments

siiron picture siiron  路  7Comments