Questions tagged [globals]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
2 answers
36 views

Can I define and use global variables within content fields?

I'd like to set a variable like "totalCustomers" and then use this throughout our content in different pages and content blocks so that there is one source of truth. Is that possible? e.g. I ...
user avatar
  • 153
1 vote
2 answers
58 views

Globals disappeared/Queue Failed — Propagating global sets

In desperate need of some help! I noticed on one of my multi-sites, 5 out of 8 sites have items missing in the Globals sidebar.. When I manually type in the URL to view one of the global items I get: ...
user avatar
  • 109
2 votes
1 answer
100 views

Get global variable value PHP

In twig, I can get the value this way, globalWebsite.freeTrialPeriodDays I need to get this value in PHP, but cleary this won't work; $trialDays = \Craft::$app->getGlobals()->getSetByHandle('...
user avatar
0 votes
0 answers
31 views

Troubleshooting General Slowness?

We have a Global page that has about 10 tabs with a bunch of fields each. The thing takes between 50 and 80 seconds to load. The debugger shows that it fires off over 9000 events and makes almost 900 ...
user avatar
1 vote
1 answer
84 views

How to directly access translated variables by language

I have a localized, two language site (en and fr) that I have a translated global variable set for. My question is: is there a way on a Craft 3 template to directly access a translation of a variable ...
user avatar
2 votes
0 answers
69 views

Manipulating globals for multi-site?

I'm working on one Craft project with two sites (which have one shared page that is translated and possibly more in the future.) Is there a way to make the global header & footer for Site 2 ...
user avatar
  • 21
1 vote
1 answer
260 views

How do I get the siteName in a module (Craft 3)

In templates I can do something like {{siteName}}. But how do I retrieve this in a module? I've tried: Craft::$app->config->siteName I can grab my custom globals via Craft::$app->globals, but ...
user avatar
0 votes
0 answers
129 views

Error when setting field length on global

I have set up several globals to store the URLs of a company’s social media accounts. Each one is a plain text field, and each one is limited to 254 characters. This works fine with three of them, but ...
user avatar
  • 176
1 vote
2 answers
385 views

Is there a way to eager-load fields in a global set?

I use a header global set to store various thing about my site header, including the company's logo. I use it in my template like this: {{ header.globalSetsHeaderLogo.one()logo.getImg() }} Any idea ...
user avatar
  • 1,130
0 votes
1 answer
110 views

Accessing global field values in site loop

I have a drop down select that I am populating with sites. I've added a lightswitch field (handle 'showInDropDown') to the global set 'siteInfo' with the hope of getting the lightswitch value per site ...
user avatar
  • 1,886
1 vote
1 answer
53 views

Show a list of pages but hide the current page from the list

My setup I'd like to show a navigation menu listing all my page entries. In my layout file, I include a template for the navigation: _layout.twig: <main> <section id="nav"> ...
user avatar
  • 123
1 vote
1 answer
244 views

Use Craft globals for CSS styles

Is it possible to pass a value from Craft global setting into a CSS/SCSS file? So for example I want to be able to allow the end user to customise colours and fonts without having to include it inline....
user avatar
2 votes
1 answer
162 views

Updating global set from controller

This is my code: $giveaway = Craft::$app->globals->getSetByHandle('promotions'); $giveaway->giveawayName = "New Name"; $success = Craft::$app->globals->saveSet($giveaway); return($...
user avatar
  • 545
2 votes
2 answers
170 views

What is appropriate for a Global field in terms of site speed?

I'm worried that if I put too much in globals, I will impact the speed of my site by a lot. For example, I was thinking of putting content in there like matrices for team members (text and image), ...
user avatar
1 vote
1 answer
31 views

Can I use a Global Variable for date/time?

The goal is to create a global variable that allows the user to specify how they would like to format the date/time for entries. I'd like to remove the hardcoded format shown here: {{ entry.postDate|...
user avatar
1 vote
0 answers
265 views

Craft 3 Cannot Save Global Set

I am playing around with Craft 3 and for the life of me cannot get it to save an element programmatically. I am trying to save a Global Set from a module like so: $config = [ 'name' => "My ...
user avatar
1 vote
1 answer
68 views

Access table from Globals in script

In the Globals I have a field which is of type table. I was trying to access this table in the javascript in order to get the values of particular rows. <script> var myTable = "{{ ...
user avatar
1 vote
1 answer
75 views

Translating checkbox labels

I'm trying to translate the labels for a global checkbox field in my front-end templates like in this post: Is there a way to have checkbox field labels translatable?. This looked promising but I can'...
user avatar
1 vote
1 answer
140 views

SEOmatic and Global Variables

We have a Craft site with nearly 800 entries. For SEO purposes we need to change the page title and page (SEO) description for each entry, a laborious task to say the least. Is there a way to have, ...
user avatar
  • 13
1 vote
1 answer
45 views

Accessing global set's field gives object that couldn't be converted to string

I've been using globals many times but this is my first time encounter with such problem. Let's go from the bottom. I have two global sets with handles tax and company. The Tax set have only one plain ...
user avatar
1 vote
1 answer
59 views

How can I make related entries and globals part of the search considerations?

How can I make related entries and globals part of the search considerations? So I have a website search bar that searches the whole website. Within some jobs pages there are some global elements ...
user avatar
  • 1,824
1 vote
1 answer
794 views

How to edit a global footer link

In the footer at the bottom of my page, www.soldierswish.org, there are two links for 501c3 and Form 990. Is there no way to edit these from the GUI? How do I edit these links?
user avatar
1 vote
1 answer
434 views

Getting image url from globals asset field

I can retrieve only the image title from the below code, I can't see why the image URL is showing as empty? its a global handle 'brand' and asset field 'logo': {% set image = brand.logo.one %} <a ...
user avatar
  • 447
2 votes
1 answer
309 views

Comparing date field object with global variable "now" gives unexpected result

The goal is to show a word when date field qualifies for tomorrow or today instead of numeric date. Setting and calling variables: {% set deliveryDate = order.deliveryDate %} {% set tomorrow = now|...
user avatar
0 votes
1 answer
89 views

Global field duplicated

I have two sites. Everytime I add global field content (slogan for example) it adds the same to the second site, and vice-versa. Anyone has any idea how to stop that?
user avatar
  • 25
1 vote
1 answer
628 views

Get globals from other sites

How would I get the global variables associated to other sites? For example, in an instance where I have three websites under the group languages for the English, Spanish, and French versions. I have ...
user avatar
  • 1,369
1 vote
1 answer
409 views

Best practise to use translate in admin panel

I am using a lot of translation with the |t / |translate filter. But the client wants to be able to edit those translations in the admin panel. So, I thought about different ways to achieve that. ...
user avatar
  • 196
1 vote
1 answer
358 views

Defining TwigExtension globals in Craft 3

A long time ago I asked how I could utilise the getGlobal method in Craft 2.x. I'd like to know how best to do this in Craft 3?
user avatar
  • 2,265
1 vote
2 answers
804 views

Access global field content

What could be the reason for this error when I’m targeting a global field?: Impossible to access an attribute ("footer") on a boolean variable (""). I created a global set Footer with a matrix ...
user avatar
  • 215
1 vote
1 answer
260 views

Saving fields to a GlobalSet

Can anyone suggest on how to programatically save fields to a GlobalSet? I’ve been following this: Programatically Adding Fields to a Layout But, doesn’t seem to work with a global? I am doing the ...
user avatar
  • 610
3 votes
1 answer
306 views

Use Globals in email templates

I’ve set up a few email notifications to be sent to customers, and in the corresponding email templates I’d like to use content from Global fields I’ve created. But when I use the regular variable {{ ...
user avatar
  • 43
1 vote
2 answers
278 views

Trying to set an image URL using a global asset field

I've setup a global asset field so that a client can change a placeholder image that gets used throughout their website. I'm using the Imager plugin for my image transforms. The following image code ...
user avatar
  • 665
1 vote
1 answer
75 views

Globally share variables

I have 4 main template folders, under the /craft folder (each template folder works for another subdomain). Now, I do have per template folder, a few variables that I like to have shared amongst all ...
user avatar
  • 465
2 votes
1 answer
37 views

I want to display entries that have a field that is the same as a field in a global variable

There is a publishMonth (multiselect) and publishYear (radio buttons) field in each article. They do not correspond to an actual date. Each article is is associated with one year, or one or more ...
user avatar
  • 67
5 votes
0 answers
178 views

Eagerloading Matrix fields resulting in empty array

I'm trying to eager-load a Matrix field with it's blocktype and related field types. For some reason the _eagerLoadedBlockTypeElements are empty arrays. If I get rid of the with clause on ...
user avatar
  • 51
4 votes
1 answer
589 views

Use global values in the Entry URL Format field

I'm trying to use global variables in Entry URLs generated by Craft, but they seem to be empty. Not getting any errors as such, just null. My Entry URL format looks like this: {{siteDefaults....
user avatar
2 votes
1 answer
205 views

Is There a Way to Add Tabs in Global Fields?

I see that it is not possible to add tabs to Global fields (unlike, say, with entries, where one can organize one's fields into different tab groups). Is there a way (without editing the core files) ...
user avatar
  • 135
0 votes
1 answer
67 views

Is it Possible to Use Live Preview with Global Settings

I know that out of the box one cannot use Live Preview with Global Settings. I am wondering if it is possible to write a plugin or in some other manner get Live Preview to work with Global Settings.
user avatar
  • 135
1 vote
1 answer
119 views

Order PDF in back-end error with Globals

I have created a PDF template for orders and this works fine on the front-end. However, when I click to Download PDF through the admin panel in an order. I get an error that: Variable "companyInfo" ...
user avatar
  • 1,824
0 votes
0 answers
50 views

Custom Messages including variables in global field?

Is it possible to setup messages (for transactional emails) as global text fields that include variables such as {{ firstName }}, {{ lastName }}, {{ email }} etc.? For example: Custom plugin fires ...
user avatar
  • 1,685
0 votes
2 answers
2k views

Create an Array in Twig and loop through fields in global set

So I've created a globals set (socialMedia) with 10 input fields, but this could grow in the future, for clients to add links to various social media accounts. This works fine except that the code for ...
user avatar
  • 1,907
4 votes
1 answer
546 views

Does Twigs 'addGlobal' exist in Craft?

I know Craft gives us access to Twigs getTwig template service; so when I attempt to use the addGlobal function like so: craft()->templates->getTwig()->addGlobal('var', $var); ... nothing ...
user avatar
  • 2,265
1 vote
1 answer
454 views

Failed to add a custom field in settings

I'm trying to add a global set, with a Matrix and two required fields for a product. This always works. Now that I am in version 2.6.2791 it fails to add the fields with error: Warning</b> : ...
user avatar
  • 353
3 votes
2 answers
296 views

Best Method of Handling Repeated Content Within Existing Fields?

We are trying to find the best solution for handling repeated content within existing Fields in the CMS. That is, there are bits of information which could be used nearly anywhere within existing ...
user avatar
  • 480
2 votes
2 answers
259 views

Using a Dropdown field in a Matrix to parse a global

I have two globals setup for affiliate and compensated type language - using Matrix and a dropdown I'm trying to find a way to let the user add this language in a new block. I cannot for the life of ...
user avatar
2 votes
1 answer
1k views

Accessing global sets from Element API

Is there an easy way to access global sets from an Element API endpoint, so its content can be included in the JSON response?
user avatar
2 votes
1 answer
665 views

How to get field values from Global Set using Element API plugin?

I'm pulling data from a Global Set using the Element API plugin and am wondering if there's a cleaner way to write the transformer function? My craft/config/elementapi.php file looks like this: <...
user avatar
  • 394
1 vote
1 answer
141 views

How can I get a field's value from a global based on a url segment?

I have a rich text field with a handle of myTextField that I have included in a global set called firstGlobalSet. What If I created another global set called secondGlobalSet and included the same ...
user avatar
  • 4,696
1 vote
1 answer
340 views

Update globals Matrix via a plugin

We are working on a plugin that needs to update the contents of a Matrix field within Globals. I've found little snippets of code but none that do exactly this. Can anyone provide some code or point ...
user avatar
2 votes
2 answers
201 views

Can I use isEditable() on a global?

I have a headline global. I am trying to see if headline is editable by using this code block, but it is not working. Can I use isEditable() with my headline global? {% if headline.isEditable() %} ...
user avatar
  • 117