You will need to access a few things.
- The url segment you need (for example the last segment)
- The global set name
- The field handle name
You can use getLastSegment to access the last url segment.
Using the global set names above let's say I have a url like this:
mysite.com/first
{% set segment = craft.request.getLastSegment() %} // first
I know I've got a global set called firstGlobalSet
, and now I've got first
. We just need to put them together. You can use Craft's
getSetByHandle method to access the global set via its handle.
{% set global = craft.globals.getSetByHandle(segment ~ 'GlobalSet') %}
{{ global }} // firstGlobalSet
Now that we've got the correct global set, we can get to the field we need. In this case it's myTextField
.
{{ global.myTextField }}