Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templater example not working #32

Closed
Lacrymology opened this issue Feb 13, 2023 · 2 comments
Closed

Templater example not working #32

Lacrymology opened this issue Feb 13, 2023 · 2 comments

Comments

@Lacrymology
Copy link

I'm just starting with obisidan, so it's perfectly possible that I'm missing something obvious.

When using the example provided at https://ntawileh.github.io/obsidian-google-lookup/person/#using-templater templater doesn't seem to run.

With this template:

<%*
  let json = {{json}}
  let firstName = json.firstName
  let emails = json.emails.join("\n")
  let relations = json.relations.map(({person, type}) => `${firstName} is a ${type || ''} relation to ${person}`).join("\n")
-%>

my contact's first name is <% firstName %>
emails:
<% emails %>

relations:
<% relations %>

date: <% tp.file.creation_date("YYYY-MM-DD HH:mm:ss") %>

<% tp.file.cursor() %>

I get the following output (some data redacted):

<%*
  let json = {
  "accountSource": "**@**.com",
  "resourceName": "people/**",
  "displayNameLastFirst": "**, **",
  "firstName": "**",
  "lastName": "**",
  "middleName": "",
  "type": "CONTACTS",
  "emails": [
    "**@**.com",
    "**@gmail.com",
    "**@**.dev",
    "**@**.com",
    "**@gmail.com",
    "**@**.dev"
  ],
  "phones": [],
  "birthdays": [],
  "relations": [],
  "userDefinedData": [],
  "clientData": [],
  "urls": [],
  "bio": "",
  "addresses": [],
  "nicknames": [],
  "contactGroupMembership": [
    "contactGroups/myContacts"
  ],
  "domainMembership": true
}
  let firstName = json.firstName
  let emails = json.emails.join("\n")
  let relations = json.relations.map(({person, type}) => `${firstName} is a ${type || ''} relation to ${person}`).join("\n")
-%>

my contact's first name is <% firstName %>
emails:
<% emails %>

relations:
<% relations %>

date: <% tp.file.creation_date("YYYY-MM-DD HH:mm:ss") %>

<% tp.file.cursor() %>

I tried removing the {{json}} and just setting it to a json object with some dummy data and the same happens. If I render the mocked version with templater directly it works as expected

@ntawileh
Copy link
Owner

@Lacrymology there is a Templater command called Replace templates in active file. You need to run that at the end in order to invoke Templater and get all those bits replaced. So after you end up with the output you pasted above, bring up the command menu, find that command and execute it

@Lacrymology
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants