Hidden variable passed in via Sprig 'does not exist' when set to a comma seperated string.
See original GitHub issueQuestion
I am trying to pass in a hidden variable passed in via Sprig.
However, I am getting back the error that _sections 'does not exist'
when _sections is set to a comma separated string and passed into the sprig template.
Here is a shortened version of my code:
template.twig
{% set sections = ['features', 'blog', 'researchPapers'] %}
{{ sprig('_includes/_sprig/search-megamenu.twig', {
_sections: sections|join(','),
nameSpace: 'technical',
placeholderText: 'Search technical articles',
allOptionsLabel: 'All Sections'
}) }}
sprig.twig
{% set section = section ?? '' %}
{% set alllowedSectionHandles = _sections|split(',') %}
{% set allowedSections = alllowedSectionHandles|map(handle => craft.app.sections.sectionByHandle(handle)) %}
{% set section = section in alllowedSectionHandles ? section : alllowedSectionHandles %}
{% if alllowedSectionHandles %}
<div>
<label for="section" class="sr-only">Directory</label>
<div class="max-w-lg rounded-md shadow-sm sm:max-w-xs">
<select
sprig
id="section"
name="section"
class="pr-6 {{ classes.input }}"
>
<option value="">All Sections</option>
{% for allowedSection in allowedSections %}
<option value="{{ allowedSection.handle }}" {{ allowedSection.handle == section ? 'selected' }}>
{{ allowedSection.name }}
</option>
{% endfor %}
</select>
</div>
</div>
{% endif %}
When I dump dd(_sections)
I get the array outputted.
if I pass in just a single string as _section. All is ok and works.
What am I doing wrong?
Issue Analytics
- State:
- Created 2 years ago
- Comments:10
Top Results From Across the Web
RequestParam variables return a set of comma separated ...
This is a bug in your JSP page. You likely have a hidden and an input with the same name. This results in...
Read more >Spring Security: Authentication and Authorization In-Depth
You can use this guide to understand what Spring Security is and how its core features like authentication, authorization or common exploit ...
Read more >Web on Servlet Stack - Spring
String that is passed to the context instance (specified by contextClass ) to indicate where contexts can be found. The string consists potentially...
Read more >Jdbi 3 Developer Guide
While there is some ORM-like functionality, Jdbi goes to great length to ensure that there is no hidden magic that makes it hard...
Read more >Describing Parameters - Swagger
In Swagger, a path parameter is defined using in: path and other attributes as necessary. The parameter name must be the same as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No problem and good luck!
@bencroker - I think I have found the problem (me). I have stripped it all down and your code is working just fine. I am working on rebuilding it back up and I think the problem is a result of an include I had not updated yet (doh). I will test and reveal shortly. But I think this is the cause. Apologies for taking up your time…