1

How do I use/call globals in entries? Trying to insert a simple global called {{ whateveryounameit }} with some text but don't see anything except its name.

Any other ways to display common content across multiple entries?

1

3 Answers 3

4

You call globals with the globals' handle, and the field name of a field in it. So, if you have a text input field named "myField" inside a global with handle "myGlobal", you can call it anywhere in your templates with:

{{ myGlobal.myField }}
2
  • Thanks but none of your solutions works for me. I'm trying to call globals within an entry not in the template and the related entries approach is too complicated and not really what I'm looking for. Any other ideas?
    – Mark H.
    Commented Aug 28, 2014 at 0:08
  • I'm confused? What do you mean "within an entry"? In the control panel? You can't put anything inside an entry since an entry isn't... anything. Do you mean that you want to use the value of a global inside a text input field in an entry, or something? Commented Aug 28, 2014 at 7:29
1

if globals don't work for you could create a related entry field that allows you call up previously created content (related blog or news posts as an example). This way you can but reference the same content through multiple entries but only have to create it once.

Here's the Craft docs for Relations

2
  • Could you expand on how this would work? I have created a matrix block I use on a parent page, but now want to have exactly the same block on each child page. I don't want to hardcode, but I don't want to make the user have to add it for each child page. Commented Aug 26, 2015 at 11:29
  • Only way to do it would be to separate that matrix field and create it as it's only channel. Then inside whatever secondary entry, create a relationship field that points to that particular matrix field/entry. You'll end up isolating your content but you can use the same content in multiple locations. Commented Aug 27, 2015 at 1:31
1

The answer is detailed here: Reference tags inside Matrix textfield

You'll need to use the global set's element ID as the reference part (second segment) of the reference tag:

{globalset:51:siteUrl}

To find the global set's ID, go to CP -> Settings -> Globals. The URL to the global set will have the ID as the last segment (e.g. http://yoursite.craft.dev/admin/settings/globals/51)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.