Questions tagged [globals]
The globals tag has no usage guidance.
83
questions
2
votes
0answers
16 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 ...
1
vote
1answer
71 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 ...
0
votes
0answers
24 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 ...
1
vote
2answers
60 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 ...
1
vote
0answers
15 views
Craft CMS project.yml not syncing correctly
I am using the latest version of Craft CMS with 'useProjectConfigFile' enabled.
My development process involves creating/updating Craft settings locally, committing this to Git and then deploying to ...
0
votes
1answer
31 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 ...
1
vote
1answer
14 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">
...
1
vote
1answer
59 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....
1
vote
1answer
33 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($...
2
votes
2answers
161 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), ...
1
vote
1answer
25 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|...
2
votes
0answers
186 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 ...
1
vote
1answer
45 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 = "{{ ...
1
vote
1answer
54 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'...
1
vote
1answer
85 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, ...
1
vote
1answer
28 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 ...
1
vote
1answer
41 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 ...
1
vote
1answer
551 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?
1
vote
1answer
342 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 ...
2
votes
1answer
236 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|...
0
votes
1answer
72 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?
2
votes
1answer
457 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 ...
1
vote
1answer
329 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. ...
1
vote
1answer
296 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?
1
vote
2answers
614 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 ...
1
vote
1answer
195 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 ...
3
votes
1answer
282 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 {{ ...
1
vote
1answer
211 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 ...
1
vote
1answer
69 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 ...
2
votes
1answer
33 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 ...
4
votes
0answers
145 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 ...
4
votes
1answer
529 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....
2
votes
1answer
184 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) ...
0
votes
1answer
64 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.
1
vote
1answer
113 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" ...
0
votes
0answers
49 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 ...
0
votes
2answers
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 ...
4
votes
1answer
486 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 ...
1
vote
1answer
443 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>
: ...
3
votes
2answers
245 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 ...
2
votes
2answers
201 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 ...
2
votes
1answer
970 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?
2
votes
1answer
603 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:
<...
1
vote
1answer
122 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 ...
1
vote
1answer
303 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 ...
2
votes
2answers
180 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() %}
...
3
votes
3answers
1k views
How to parse environment variables and globals from a field
I want the ability to parse environment variables such as {siteName} and globals from channel fields, for example a rich text field.
I have been using {{ include(template_from_string(entry.fieldName)|...
2
votes
2answers
696 views
How do I check if a Global field exists in a template?
In a template, can I check whether a Global field exists, before I try to output its value? I want to ensure the page doesn't break entirely in the unlikely event of the field being removed from the ...
2
votes
1answer
696 views
Calling an Asset field from a Global
I can't, for the life of me, find an answer to this question.
I have a global called work. It has three Asset fields. One is called mediakit, which is an upload of a PDF. I am trying to get the ...
5
votes
1answer
356 views
Globals versus Singles
We are building a restaurant site that has a banner image and some introductory text on each page. For pages that include content from a Channel, e.g. the wine list, we are using a Global to define ...