[FR] - Add a `__toString` method which will just output the code field value
RyanRoberts opened this issue · 3 comments
Describe the bug
I get the following error:
Object of class nystudio107\codefield\models\CodeData could not be converted to string
Here's a screenshot: https://media.yep.digital/l3J4N3
I have a global set with a field for script tags, I'm outputting this in the base layout file with {{ meta.headScripts|raw }}
. Nothing fancy going on.
The field settings are default except for:
- Code Field Theme: Visual Studio Light
- Code Field Default Language: HTML
- Show Language Dropdown with Field: Unchecked
This happens with and without content, also on a completely new field.
Versions
- Plugin version: Code Field 4.0.5
- Craft version: 4.3.5
I have a global set with a field for script tags, I'm outputting this in the base layout file with {{ meta.headScripts|raw }}. Nothing fancy going on.
You need to be doing what the docs say:
https://nystudio107.com/docs/code-field/#using-code-field
{{ meta.headScripts.value|raw }}
Though you raise a good point -- I could add a __toString
method that just does this for you.
Ah I'm sorry, I overlooked value
!
Nah it's reasonable that people would do this, so I added a __toString()
method to CodeData
so that what you did will work.
Craft 3: Version 3.0.6 -> https://github.com/nystudio107/craft-code-field/releases/tag/3.0.6
Craft 4: Version 4.0.6 -> https://github.com/nystudio107/craft-code-field/releases/tag/4.0.6