Skip to content

fix(timber): reset default context handling in renderComponent function#617

Open
mahmoud-alawad wants to merge 2 commits intoflyntwp:masterfrom
mahmoud-alawad:fix/nested-component-context-inheritance
Open

fix(timber): reset default context handling in renderComponent function#617
mahmoud-alawad wants to merge 2 commits intoflyntwp:masterfrom
mahmoud-alawad:fix/nested-component-context-inheritance

Conversation

@mahmoud-alawad
Copy link

No description provided.

@timohubois
Copy link
Contributor

@mahmoud-alawad many thanks for the pr. It contains a TODO comment and also i am unsure about what will be the benefit of the changes? Could you please make a review and also add a description?

@mahmoud-alawad
Copy link
Author

@timohubois This PR is related to #579

I've implemented a solution to fix the issue with inheriting data from parent components.

Changes

With this PR, developers now have full control over Twig's include options when rendering components:

{{ renderComponent('ComponentName', {data}, {includeContext: false}) }}

Available Options

Developers can now pass the following options as the third parameter:

  • includeContext (bool, default: true) - Controls whether the parent component's context variables are inherited by the child component
  • ignoreMissing (bool, default: false) - If true, no error is thrown when the component template doesn't exist
  • sandboxed (bool, default: false) - If true, renders the component in sandbox mode with restricted capabilities

Examples

{# Render component without inheriting parent context #}
{{ renderComponent('Card', cardData, {includeContext: false}) }}

{# Render component without inheriting parent context and without passing data #}
{{ renderComponent('Breadcrumbs', {}, {includeContext: false}) }}

{# Render optional component that may not exist #}
{{ renderComponent('OptionalWidget', data, {ignoreMissing: true}) }}

{# Render user-generated component with security restrictions #}
{{ renderComponent('UserTemplate', data, {sandboxed: true}) }}

This provides developers with the flexibility to control component rendering behavior based on their specific needs.

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

Successfully merging this pull request may close these issues.

2 participants