Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow named key Lists for patterns #214

Open
woldtwerk opened this issue Aug 31, 2022 · 1 comment
Open

Allow named key Lists for patterns #214

woldtwerk opened this issue Aug 31, 2022 · 1 comment

Comments

@woldtwerk
Copy link
Contributor

Hi Christian,
currently it is not possible to use pattern lists with named keys.

e.g. for putting patterns inside the page.header, page.footer variables.

page:
  use: "@namespace/layout/page.html.twig"
  namespace: "Layout"
  label: Page
  description: Page
  fields:
    page:
      type: pattern
      label: Page
      description: The Page
      preview:
        header:
          id: 'header'
        footer:
          id: 'footer'

I didn't see any problem for allowing this.

Relevant code is:

const delta: number = Number.parseInt(nameKeys[1], 10);

delta is cast to a number here. this would have to allow strings also

previewRenderedVariables[nameKeys[0]] = [];

previewRenderedVariables is initialised with an empty array. This would need to be an object if delta is a string.

Add object check in

} else if (field.getType() === 'pattern' && preview?.id) {

else if (field.getType() === 'pattern' && typeof preview === 'object') {
        Object.keys(preview).forEach(i => {
          previewPatterns["".concat(key, "--").concat(i)] = _this2.buildPreviewPattern(preview[i]);
        })

This would allow to print {{ page.header }} in templates, but not {{ page }}. Is that good enough?

If that seems alright to you I'd like to create a pull request.

@christianwiedemann
Copy link
Contributor

Hi, sorry for late answer. Somehow missed your ticket. Technical is it not a problem. But you can't use it in Drupal this. So if you use inside your pattern it would not work in drupal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants