2

I need to access just the ID of a specific section.

I do that like this and it works:

{% set enroll = craft.sections.getSectionByHandle('workshopEnrollments') %}

But when I do:

{% for e in enroll %} {{ e.sectionId }} {% endfor %}

or:

{% for e in enroll %} {{ e.id }} {% endfor %}

I get the error:

Impossible to access an attribute ("sectionId") on a string variable ("32")

However, when I view the variable inside my form what I actually see is exactly this

32Workshop EnrollmentsworkshopEnrollmentschannel1workshop-enrollments/_entry1

So my question is, how can I just display the id. Both ".id" and ".sectionId" produce the same error mentioned above.

"32" is the id I want so it is the correct return, but this seems to show everything about it in a string and I need just the id. I am using getSectionByHandle because I have no other data to use in this particular view.

Thanks for any help.

5

getSectionByHandle doesn't return an array, but a single SectionModel - so you need to remove the for loop:

{% set enroll = craft.sections.getSectionByHandle('workshopEnrollments') %}

{{ enroll.id }}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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