I have a plugin that's loaded on the edit page of an entry.

Whenever I open the entry edit page, I would like to retrieve the id of this particular entry. I've tried this: {% set someId = craft.request.getParam('entryId') %}

But this just returns null.

I need the id because I use it in my service: craft.pluginName.getRecordByEntryId(someId). Which will return information that's bound to that page.

I've also tried this:

{% for entry in craft.entries %}
{% if entry.id %}
    <p>EntryId: <input type="text" value="{{ entry.id }}"/></p>
{% endif %}{% endfor %}

But this will return all the entry id's, which I can't really use.

Any help or advice on how I should tackle this differently?

Thanks in advance!


craft()->request->getParam() is only going to check for the value as part of the query string in the URI or in POST if it is a POST request, which is why it's returning null on the edit entry page in the control panel (it isn't in either).

But since it looks like you're using a template hook in your plugin, you can get the entry id directly from the context:

$entry = $context['entry'];

if (!$entry->id)
    // New entry
    $entryId = $entry->id;

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.