Dynamic relation data defined inside template

WHAT DO YOU RECOMMEND

The user could define a formula by which, when the template is used to create an object, dynamic data is inserted into either the object itself or its relation(s).

HOW COULD IT BE DONE

Shortcode or markdown-related user input is a basic method. Obsidian uses this, for example, to insert the present date/time when a template is used to create an object. With the development of a simple formula language, more complex UI models could be used for improved UX, such as a dropdown list from the (template) editor. Obviously the more development work applied to such a model, the less user input would be required to create such variables in templates.

REAL WORLD USE CASES

In the end, the point is to use some formula or variable within a template to automatically fill data into the object or its relations when the template is triggered. Examples of user-entered formula language can be found by review of Obsidian’s template variables. There the user applies code such as {{user}}, where “user” is the variable name pulled from metadata. Another related example is Obsidian’s {{date}} variable used in templates to insert the present date at the time of the template’s application creating a new object (file).

RECOMMENDED ALTERNATIVES

Alternatively, Anytype devs could create such variables input via a UI similar to the way relations are now user-applied. Or perhaps there is a simpler way I haven’t considered.

ADDITIONAL CONTEXT

This FR relates, but does not include the concept of a dynamic formula to apply variable data at the time of object creation.

This FR includes request for suggested drop-down input that could be used for improved UI/UX.

WHAT DO YOU RECOMMEND

The ability to add a token that represents the current date/time in the title of a template.

When a new object is created, the token would be replaced with the current date.

HOW COULD IT BE DONE

Add “My Notes for {{Now}}” as the first line in a template.
When a new object is created with this template, replace {{Now}} with the timestamp.

Add formatting options {{now|YYY-mm-dd}} based on some common specification.

REAL WORLD USE CASES

Journaling, Note taking, Recording activities and events.

@MDG thanks for your post!

Could you check whether the following topic requests the same?

Yes, the Dynamic relation data defined inside template Feature Requests is a much more complete way to describe the interaction I’m interested in.

WHAT DO YOU RECOMMEND

I would like to use the [@] operator in the names of objects, to be able to set their name automatically upon creation through a template.

HOW COULD IT BE DONE

Just like you can use the [@] in a normal text block to set, for example, ‘@today’ or ‘@tomorrow’, I would like to set that for the name in the template, and get it applied upon object creation.

REAL WORLD USE CASES

I would use this feature in two different cases:

  1. I have a type called ‘Training Record’. I use it to record my progress in the gym, and I usually set the name to the current date. If the template had ‘@today’ in the template name, when I create a new training record the name would automatically be set to ‘03-10-2023’.
  2. I have a type called ‘Workplan’. I use it to layout the planning of tasks for the day, and have many for each day I need a workplan. The use case is the same as before: template with ‘@today’, and name set as the current date upon object creation.

RECOMMENDED ALTERNATIVES

Currently, this behavior isn’t even possible within the content of the object itself, which I find to be a wasted opportunity for automation.
Of course, the only alternative I see is, just as we have to do now, set those parameters manually. This works, but I believe this could be easily implemented.

Thanks for reading!

It would be cool to automate beyond just the object name.

For example, I have templates where there is a set that is filtered to only objects that have the object in a relation (eg. Book A has a set with only “Quote” objects from Book A), so it would be cool automate that (in this case, have a filter for Relation X > Has all of > @current-object).

Just expanding on this, I think basic templating variables like:

  • <% yesterday %>
  • <% today %>
  • <% tomorrow %>
  • <% current_month %>
  • <% current_year %>
  • <% current_day_name %>

But also it would be awesome to target objects or properties:

  • <% title %>
  • <% current_counter_value %>

Or would being able to put a query into a template that executes the query, returns the result value, and uses that result value in place, this way the user could build their templating variables.

It would be helpful if Templates support macros, like date. When I create a journal entry, I would like to title of the journal entry to be the creation date. Right now, I am typing in the date as the title right after it is created. It could be something like {date} in the template, or {date:YYYY-MM-DD} to enhance the format of the date.

Thoughts?

We need this…

@seanchiggins I think this is a great idea and its seems you are not the only one thinking (dreaming?) about this:

Can you let me know if I can close your topic as a duplicate?

Sure. It sounds like what I was looking for.

Closed as duplicate

Is this feature already released? if so how to put variable into template?

WHAT DO YOU RECOMMEND?

When creating a object in the set by using template, it’s really nice to have a feature to replace “keywords” to the specific values such as the followings:

  • date
    • There might be some types like YYYY/mm/dd, dd/mm/YYYY or mm/dd/YYYY
  • time
  • time12H

HOW COULD IT BE DONE?

When making a new object, replace keywords in the template.

REAL WORLD USE CASES

Allowing replacing keywords, we can start writing meeting note quickly without modifying keywords every time such as meeting period in the minutes.

Assuming variables share the same foundation as formulas, they should be developed by mid-2025. We’ll know better when next year’s roadmap is out, and let’s hope it doesn’t get pushed back because of efforts diverted to AI integration.

This is a very important pattern, I think. The example I’m running up against is a template for a Project that contains a set of Tasks that are linked to @current_project. There’s just no way to specify @current_project in the template.

+1 I’m running into a similar issue, where I’d like in my template to add a filter to a set that would filter by doing the following:

Object > Has Any Of > “This Object”

WHAT DO YOU RECOMMEND?

Allow users to use template strings in title or property values to generate actual values automatically, like @Today, @Yesterday, which can generate actual date text when the object is created

HOW COULD IT BE DONE?

A specific grammer in template content, recognize the pattern and convert it to real value when object of this template is created

REAL WORLD USE CASES

Objects using date string as title, like diaries, notes

If not auto-gen, users can only type in dates manually

Adding my reminder from 2025 - already 2 years after this thread was started:

No access to dynamic data really compromises the usefulness of templates…

But all of us (users and developers alike) need to keep in mind that what is being described here, if we take the original post plus all other comments, it’s a very complex feature set - and, therefore, very difficult and time-consuming to implement. On the other hand, improving templates usefulness is definitely not a “all or nothing” situation.

What I mean is, having a bare-bones, simple, initial implementation would already give us some leverage - not to say also very useful for the developer team to measure how important changes in that area would be to the actual, current user base.

Yes, ideally I would very much like to have access to a full script engine, which I could then use to generate complex, dynamic data in my templates, or even link the new object with other objects automagically, and so forth…

Important :backhand_index_pointing_down:

But if we start by, say, just supporting dynamic references to date shortcuts, which already exist in a “static” way, such as @today or @yesterday, that would already help me and many other folks a lot…!!!

I could be wrong, but there has been no movement whatsoever in the direction of making templates more dynamic
Templates are, pretty much since the beginning, just a way of adding static data to a new object.

And that’s why I say that, at this point anything, even a simple, small new feature, only about adding support to dynamic dates, would help us A LOT already.

Any update on this?