Skip to content

Fix: reset default context handling in renderComponent function #580

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/Utils/TwigExtensionRenderComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Flynt\Api;
use Flynt\ComponentManager;
use Timber\Timber;
use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\Extension\CoreExtension;
Expand Down Expand Up @@ -43,7 +44,7 @@ public function getFunctions()
*
* @return string The rendered component.
*/
public function renderComponent(Environment $twigEnvironment, array $context, $componentName, ?array $data = [], bool $withContext = true, bool $ignoreMissing = false, bool $sandboxed = false)
public function renderComponent(Environment $twigEnvironment, array $context, $componentName, ?array $data = [], bool $withContext = false, bool $ignoreMissing = false, bool $sandboxed = false)
{

$data ??= [];
Expand All @@ -52,8 +53,9 @@ public function renderComponent(Environment $twigEnvironment, array $context, $c
$data = array_merge($componentName, $data);
$componentName = ucfirst($data['acf_fc_layout']);
}
$timberContext = $withContext ? $context : Timber::context();

$fn = function ($output, $componentName, $data) use ($twigEnvironment, $context, $withContext, $ignoreMissing, $sandboxed) {
$fn = function ($output, $componentName, $data) use ($twigEnvironment, $timberContext, $withContext, $ignoreMissing, $sandboxed) {
$componentManager = ComponentManager::getInstance();
$filePath = $componentManager->getComponentFilePath($componentName, 'index.twig');
$relativeFilePath = ltrim(str_replace(get_template_directory(), '', $filePath), '/');
Expand All @@ -68,7 +70,7 @@ public function renderComponent(Environment $twigEnvironment, array $context, $c

$loader->addPath(dirname($filePath));

$output = CoreExtension::include($twigEnvironment, $context, $relativeFilePath, $data, $withContext, $ignoreMissing, $sandboxed);
$output = CoreExtension::include($twigEnvironment, $timberContext, $relativeFilePath, $data, true, $ignoreMissing, $sandboxed); //TODO: CoreExtension::include: review withContext parameter

$loader->setPaths($loaderPaths);

Expand Down