Code Monkey home page Code Monkey logo

Comments (3)

velomovies avatar velomovies commented on July 18, 2024 1

Hi @johannesmutter!

At the moment there is no direct way to get the id of a record.

There is, however, a work around. Since you can run any code in this plugin you could for now handle this by using this (which would be the window) and initiate a plugin inside the plugin. You will get all plugin options and methods and thus it will give you access to plugin.itemId.

let recordId
await this.DatoCmsPlugin.init((plugin) => {
  recordId = plugin.itemId
})

return `${title ? title : 'untitled'} ${recordId}`

All options and methods you get returned are listed here: https://www.datocms.com/docs/building-plugins/sdk-reference
I hope this helps you!

from datocms-plugin-computed-fields.

velomovies avatar velomovies commented on July 18, 2024 1

When updating to version 2.0 of the computed fields plugin this won't work anymore. In version 2.0 there will be a datoCmsPlugin variable.

datoCmsPlugin will return the whole plugin context. In the documentation you can see what properties and methods are exposed. The datoCmsPlugin variable is ctx of a field extension with the declared type: RenderFieldExtensionCtx.

You can do

return datoCmsPlugin.itemId

or in the example of this issue

const recordId = datoCmsPlugin.itemId
return `${title ? title : 'untitled'} ${recordId}`

from datocms-plugin-computed-fields.

johannesmutter avatar johannesmutter commented on July 18, 2024

Awesome! Thank you

from datocms-plugin-computed-fields.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.