craftcms / guest-entries

Accept anonymous entry submissions with Craft.
MIT License
106 stars 26 forks source link

How to find a section's UID #75

Closed darylknight closed 1 year ago

darylknight commented 1 year ago

Not a bug - but there's no discussion option for this repo. I'm setting this up for the first time and the docs say you need to change the hidden input to the section's UID. There is no way to find this in the control panel as far as I can tell. If you edit a section, you get the section's ID (4). Could we add something to the docs of this plugin or Craft's docs that describe how to find a section's UID please? I'm trawling through the project config files but I can't immediately tell from there which ID I'm meant to use either.

i-just commented 1 year ago

Hi, you’re right; it’s not that easy to find at first glance.

The section’s UID is in the file’s name in config/project/sections. For example, I have a section with a handle of mySection, and the project config filename is: mySection--b6ef4bae-8a6d-45fa-8764-7456719485aa.yaml, which means the section UID is b6ef4bae-8a6d-45fa-8764-7456719485aa.

You can also find this by getting the section by ID or handle and then fetching its UID from what’s returned (in a plugin or a module): Craft::$app->sections->getSectionById() or Craft::$app->sections->getSectionByHandle().

Or by getting an entry from that section and then getting its section and UID from there, which can be done in your templates too: {{ craft.entries.slug('test1').one().section.uid }}.

Hope this helps!

darylknight commented 1 year ago

Got it, thanks!

AugustMiller commented 1 year ago

Thanks for flagging this, @darylknight!

I've reworked the readme to reflect the available options—and in the process discovered that we actually support sending a Section’s handle, directly:

{{ hiddenInput('sectionHandle', 'mySection') }}

For the sake of closing the loop on your question—@i-just’s PHP API example can be replicated in Twig, like this:

{% set section = craft.app.sections.getSectionByHandle('mySection') %}

{{ hiddenInput('sectionUid', section.uid) }}
darylknight commented 1 year ago

That's great, thank you for the extra info