Comments (3)
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.
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.
Awesome! Thank you
from datocms-plugin-computed-fields.
Related Issues (17)
- Not returning anything HOT 5
- How to access Local based content? HOT 2
- RTL behaviour of the field
- Not published correctly? HOT 3
- Adding computed fields for existing content HOT 1
- Missing environment ID causes issues in non-primary environments HOT 1
- Computing a link field HOT 1
- Allow getFieldValue to return object HOT 2
- Properly hide or disable the field HOT 4
- Where does console.log show up? HOT 1
- Does not work as part of Blocks HOT 4
- How to access values within multi-link field? HOT 3
- Script not firing on field value change. HOT 3
- Computed field is not recalculated when modifying fields of sibling (block) HOT 2
- Usage on an Single Asset field causes Display Editor to become locked; unable to switch back to default HOT 4
- Problem with supporting multiple locales.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from datocms-plugin-computed-fields.