Templater Syntax issue

Things I have tried

What I’m trying to do

I have trying to create a template and I want to have the option when I choose something specific. In this case the word Mortal to have some additional option as the Photo shows.

Also I trying to Find a way to, while creating the new note to add the Title and to retrieve some data and make them as tags

Is that possible??

I see several problems

  1. This appears to be a header (i.e. in edit mode it looks like # Character). If this is case, it must come after the YAML block.
  1. YAML keys containing a dot (period character) are allowed but can be problematic. I suggest renaming to Number instead of abbreviating.
Sex <% await tp.system.suggester(["Male","Female"], ["Female","Male"]) %>
  1. There needs to be a colon after the word ‘Sex’. Otherwise it won’t be a valid YAML item.
  2. The first array in the suggester function is the list of options displayed for selection. The second array is what value is actually returned. The way this is written, the user will select Male but the displayed value will be Female. Maybe you intended to gender flip things?
Kind <% await tp.system.suggester(["God", "Titan", "Giant", "Monster", "Mortal", "Nymph", "Primordial"], ["God", "Titan", "Giant", "Monster", "Mortal", "Nymph", "Primordial"]) %>
  1. There needs to be a colon after the word ‘Kind’. Otherwise it won’t be a valid YAML item.
Mortal: <% tp.frontmatter.["Mortal" await tp.system.suggester(["Mereo", "King", "Villain"], ["Mereo", "King", "Villain"]) %>]
  1. The closing ] that matches the first [ is outside the Templater closing%>. It needs to be inside. Definite parser error.
  2. Even if the bracket was in the correct place, the "Mortal" text followed by tp.system.suggester is another parser error.
  3. At this point, the frontmatter for Mortal has not been defined. In fact, I doubt any of the keys have been defined in the tp.frontmatter construct. Templater is still in the process of creating the note.

To fix, I suggest this Templater template:

const name = await tp.system.prompt('Character Name');
if (tp.file.title.startsWith('Untitled')
   await tp.file.rename(name);
const sex = await tp.system.suggester(["Male","Female"],["Male","Female"]);
const kind = await tp.system.suggester(["God", "Titan", "Giant", "Monster", "Mortal", "Nymph", "Primordial"],["God", "Titan", "Giant", "Monster", "Mortal", "Nymph", "Primordial"]);
let mortal = '';
if (kind == 'Mortal') mortal = tp.system.suggester(["Mereo", "King", "Villain"],["Mereo", "King", "Villain"]);
Date: <% tp.date.now("Do MMMM YYYY") %>
Sex: <% sex %>
Kind: <% kind %>
Mortal: <% mortal %>
# <% name %>

   - When: 
   - Where: 
   - Alt. Name:
   - Greek Name:
   - Latin Name: 
   - Kind: <% kind %>
   - Sex: <% sex %>
   - Father: 
   - Mother: 
   - Brothers: 
   - Sisters: 
   - Spouse: 
   - Children:
   - Rule: 
   - Symbols: 
   - Transformation: 
   - Weapon: 
   - Abilities: 
   - Character: 
   - Constellation: 
   - Beat It By:
   - Saved By:
   - Stories: 

1 Like

Thank you a lot about all this!

I end up with this

The first part, regarding the title, it never function for me, but I don’t need it.

Is possible to make even more comprehensive ?
What I mean is is for example for the Nymph I choose Aurae
The Aurea to give an additional option to be equal with Breeze for example?

I notice that you’re bound to end up with lines with raw hash marks (in your image for example, Mortal: #) If you’d like to avoid that, try a construct like the following:

- Mortal: <%* if (mortal != '') tR += `#${mortal}`; %>

Using <%* as opposed to <% means that we’re going to engage in a bit of JavaScript code. And tR is a Templater variable that is used to collect content that is to be output to the realized template.

Slightly more complicated, you can avoid outputting lines all together when they have no value (i.e. they don’t apply to this character such as a Nymph not needing a Mortal value.)

<%* if (mortal != '') tR += `- Mortal: #${mortal}\n`; -%>

Using -%> avoids leaving a blank line that this would normally leave, but it then means we have to include the line return \n in the output text.

As to your question, sure, you can make it more comprehensive. I’m not sure I understand your example, but you could certainly do something like the following (I’m just guessing what values breeze might have here):

let nymph = '';
let breeze = '';
if (kind == 'Nymph')
   nymph = tp.system.suggester(['Aurae','River','Tree'],['Aurae','River','Tree']);
   if (nymph == 'Aurae')
      breeze = tp.system.suggester(['North Wind','South Wind','West Wind','East Wind'],['North Wind','South Wind','West Wind','East Wind']);

I’m just toying with an idea here, but would it be true to say that given the kind (like “Mortal”), there is always a smaller set of specification for that kind, so it’s something of a sub-kind or kind-specifier?

And taking that another step, would it better to actually just have those two instead of the entire list of “God”, “Mortal”, “Nymph”, … , and all the other kinds?

If this would be the case, I also envision doing this a whole lot simpler with basically a two-dimensional list like:

const kinds = {
  "God" : [ "God", "Godess" ],
  "Titan" : [ "Titan", "Titaness" ],
  "Mortal" : [ "Mereo", "King", "Villain" ],
  "Nymph" : [ "Aurae", "River", "Tree" ]

This could be combined into a template with only two suggester’s like in the following:

const kinds = {
  "God" : [ "God", "Godess" ],
  "Titan" : [ "Titan", "Titaness" ],
  "Mortal" : [ "Mereo", "King", "Villain" ],
  "Nymph" : [ "Aurae", "River", "Tree" ]

const kind = await tp.system.suggester(
    (i) => i, Object.keys(kinds),
    false, "Which kind is it?")
const kind_specifier = await tp.system.suggester(
    (i) => i, kinds[kind],
    false, `What kind of a ${ kind } is it?`)
kind: <% kind %>
kind-specifier: <% kind_specifier %>

Which would lead to an output like:

Thank you both! I will try them ASAP !!