Inside a JSON template I find an entry using id, the result title can't be seen using entry.title but I can see it with entry[0].title. There is another step or encoding I have to use?


If you are using something like this to get your entry:

{% set entry = craft.entries.section('blog').limit(1).id('21') %}

then Craft is actually returning an ElementCriteriaModel object, even if it is only one entry.

To ensure that the entry variable only contains a single entry, you need to call the first() method like this:

{% set entry = craft.entries.section('blog').limit(1).id('21').first() %}

More details in the docs here: https://craftcms.com/docs/templating/elementcriteriamodel

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.