Questions tagged [scope]
The scope tag has no usage guidance.
8
questions
0
votes
0
answers
23
views
Variable scope in Element API
I am using the Craft Element API and getting a bit muddled over PHP variable scopes.
I was hoping if someone could please explain why this does not work:
$isProd = App::env('ENVIRONMENT') === '...
1
vote
1
answer
63
views
Adding entries to the top level scope of a variable in Twig
I have made a frontpage editing system where the user can desk a frontpage, adding news items and other blocks manually. One of the blocks is "Last n news items". I would like this to ...
1
vote
1
answer
116
views
Use Service Worker in Plugin
I am currently working on a plugin that uses a service worker which gets registered on the front-end by some javascript code and the problem is that the service worker scope is restricted to /...
1
vote
0
answers
225
views
making a dynamic menu in a template
Sometimes the links are in-page, sometimes they point outside. I want to be able to create an array menuitems that is passed to an include and which then generates a per-section index menu on the page....
1
vote
1
answer
2k
views
How to set and test a variable in child template to modify a block in parent template
I would like to load some javascript on specific pages only.
I'm trying to set a block in my parent template, then test a variable and include the javascript in the child template only when necessary....
1
vote
2
answers
217
views
Problem with scope in macro
I've written a short macro to get the first image inside a matrix field.
{% macro firstImage(entry) %}
{% set image = 'hello' %}
{% if entry.sliderMatrix.total() %}
{% set block = ...
5
votes
1
answer
151
views
How are changes to the dashboard scoped?
I'm working on a Craft project with another developer. We're connected to the same shared database but my dashboard is different than his (I customized mine).
This made us wonder how the custom ...
9
votes
2
answers
32k
views
Is there a way to define a global var within a twig block?
Something that would work like this:
{% block A %}
{% set testVar = "foo" %}
{% endblock %}
...
{% block B %}
{{ testVar }}
{% endblock %}
The scope of testVar seems limited to {% block A %}
I'...