Questions tagged [scope]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
1answer
31 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
1answer
67 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
0answers
173 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
1answer
1k 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
2answers
207 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
1answer
150 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 ...
8
votes
2answers
28k 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'...