Closed atelierbim closed 1 week ago
Please check the response body, there is likely an error in your Twig template code.
I thought Spark would inject the store variable to the fragment. I apparently doesn't do it in my case:
Twig\Error\RuntimeError: Variable "search" does not exist. in /var/www/html/templates/spark/fragments/search-results.twig:4
Stack trace:
#0 /var/www/html/storage/runtime/compiled_templates/92/92725ae0a433e6d15f9df60fc755d639.php(52): __TwigTemplate_2ae6099b6bdb7e6948fdeec956e17829->{closure}()
#1 /var/www/html/vendor/twig/twig/src/Template.php(393): __TwigTemplate_2ae6099b6bdb7e6948fdeec956e17829->doDisplay(Array, Array)
#2 /var/www/html/vendor/twig/twig/src/Template.php(349): Twig\Template->yield(Array, Array)
#3 /var/www/html/vendor/twig/twig/src/Template.php(364): Twig\Template->display(Array)
#4 /var/www/html/vendor/twig/twig/src/TemplateWrapper.php(35): Twig\Template->render(Array)
#5 /var/www/html/vendor/twig/twig/src/Environment.php(306): Twig\TemplateWrapper->render(Array)
#6 /var/www/html/vendor/craftcms/cms/src/web/View.php(539): Twig\Environment->render('spark/fragments...', Array)
#7 /var/www/html/vendor/putyourlightson/craft-spark-module/src/services/ResponseService.php(93): craft\web\View->renderTemplate('spark/fragments...', Array)
#8 /var/www/html/vendor/putyourlightson/craft-spark-module/src/services/ResponseService.php(40): putyourlightson\spark\services\ResponseService->renderTemplate('spark/fragments...', Array)
#9 /var/www/html/vendor/putyourlightson/craft-spark-module/src/controllers/DefaultController.php(61): putyourlightson\spark\services\ResponseService->stream(Object(putyourlightson\spark\models\ConfigModel), Object(putyourlightson\spark\models\StoreModel))
#10 [internal function]: putyourlightson\spark\controllers\DefaultController->putyourlightson\spark\controllers\{closure}()
#11 /var/www/html/vendor/yiisoft/yii2/web/Response.php(454): call_user_func(Object(Closure))
#12 /var/www/html/vendor/yiisoft/yii2/web/Response.php(343): yii\web\Response->sendContent()
#13 /var/www/html/vendor/yiisoft/yii2/base/Application.php(390): yii\web\Response->send()
#14 /var/www/html/web/index.php(12): yii\base\Application->run()
#15 {main}
It does, but you need to call store.search
.
{% set results = craft.entries()
.section('worksChannel')
.search(store.search)
.all() %}
OK got it. Thanks Ben. Here's the updated code: in search-results.twig
{% set results = [] %}
{% if store.search is not empty %}
{% set results = craft.entries()
.section('worksChannel')
.search(store.search)
.all() %}
{% endif %}
Support Request
I setup a fresh craft install with ddev (Docker Desktop) and installed Spark plugin.
index.twig
search-results.twig
when typing in the search input I get this in the console
Here's the output:
Is there any ddev setting to do that is not in the docs? I also wanted to know if Spark is supposed to work on Craft Cloud hosting. Thanks
Plugin Version
1.0.0-alpha.5