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

Getting Internal Server error in Craft 5 when try to includeDynamic #750

Open
amici-infotech opened this issue Dec 30, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@amici-infotech
Copy link

Bug Report

{{ craft.blitz.includeDynamic("_/blitz/user-nav", {
navSection : 'desktop'
}) }}

Diagnostics Report

ERROR in logs file.

2024-12-30 06:19:51 [web.ERROR] [TypeError] TypeError: craft\web\View::renderPageTemplate(): Argument #2 ($variables) must be of type array, null given, called in ___WEB_ROOT___/vendor/putyourlightson/craft-blitz/src/controllers/IncludeController.php on line 62 and defined in ___WEB_ROOT___/vendor/craftcms/cms/src/web/View.php:576
Stack trace:
#0 ___WEB_ROOT___/vendor/putyourlightson/craft-blitz/src/controllers/IncludeController.php(62): craft\web\View->renderPageTemplate('_/blitz/user-na...', NULL, 'site')
#1 ___WEB_ROOT___/vendor/putyourlightson/craft-blitz/src/controllers/IncludeController.php(39): putyourlightson\blitz\controllers\IncludeController->getRenderedTemplate()
#2 [internal function]: putyourlightson\blitz\controllers\IncludeController->actionDynamic()
#3 ___WEB_ROOT___/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#4 ___WEB_ROOT___/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#5 ___WEB_ROOT___/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('dynamic', Array)
#6 ___WEB_ROOT___/vendor/craftcms/cms/src/web/Application.php(350): yii\base\Module->runAction('blitz/include/d...', Array)
#7 ___WEB_ROOT___/vendor/craftcms/cms/src/web/Application.php(649): craft\web\Application->runAction('blitz/include/d...', Array)
#8 ___WEB_ROOT___/vendor/craftcms/cms/src/web/Application.php(312): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#9 ___WEB_ROOT___/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#10 ___WEB_ROOT___/web/index.php(12): yii\base\Application->run()
#11 {main} {"memory":4820104,"exception":"[object] (TypeError(code: 0): craft\\web\\View::renderPageTemplate(): Argument #2 ($variables) must be of type array, null given, called in ___WEB_ROOT___/vendor/putyourlightson/craft-blitz/src/controllers/IncludeController.php on line 62 at ___WEB_ROOT___/vendor/craftcms/cms/src/web/View.php:576)"} 

Seems like this like in controller (IncludeController.php) is causing the issue

$params = Json::decodeIfJson($include->params);
$output = Craft::$app->getView()->renderPageTemplate($template, $params, View::TEMPLATE_MODE_SITE);

as $params always needs to be array, this error is throwing from craft end. I changed the code to this and it works

$params = Json::decodeIfJson($include->params);
$output = Craft::$app->getView()->renderPageTemplate($template, $params ?: [], View::TEMPLATE_MODE_SITE);
@amici-infotech amici-infotech added the bug Something isn't working label Dec 30, 2024
@bencroker
Copy link
Collaborator

Are you on the latest versions of Blitz and Craft? Please provide version numbers.

This error appears to indicate an issue with saved includes stored in the database. Can you please clear and flush the cache to reset this and verify that it is an issue in the database?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants