ntawileh / obsidian-google-lookup

Obsidian plugin that pulls contact and calendar event information from your Google account
https://ntawileh.github.io/obsidian-google-lookup
MIT License
76 stars 10 forks source link

Templater example not working #32

Closed Lacrymology closed 1 year ago

Lacrymology commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

Thanks!