# Use aliases with Templater suggester

**URL:** <https://forum.obsidian.md/t/use-aliases-with-templater-suggester/76244>\
**Category:** Help\
**Tags:** templater\
**Created:** [February 3, 2024, 3:18pm UTC](https://forum.obsidian.md/t/use-aliases-with-templater-suggester/76244 "2024-02-03T15:18:44Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![holroy](https://forum.obsidian.md/user_avatar/forum.obsidian.md/holroy/32/77699_2.png) [@holroy](https://forum.obsidian.md/u/holroy)\
**Post date:** [February 4, 2024, 4:30pm UTC](https://forum.obsidian.md/t/use-aliases-with-templater-suggester/76244/3 "2024-02-04T16:30:07Z")

</div>

Using parts of the code listed in previous post, I built the following template:

```js
  <%_*
// Get the destination file
const allFiles = await app.vault.getMarkdownFiles()
// .slice(0, 10) // Uncomment for test purposes of a smaller file set

const alternatives = []

function pushAlternative(path, basename, alias) {
  alternatives.push({ path: path, basename: basename, alias: alias})
}

allFiles.map(file => {
  const fileCache = app.metadataCache.getFileCache(file);
  // Push non-aliased alternative
  file.alias = file.basename
  pushAlternative(file.path, file.basename, file.alias)
  // Use the following to check for existence, and type of alias
  const aliasType = typeof(fileCache.frontmatter?.aliases)
  
  if (aliasType == "string") {
    // Single alias
    file.alias = fileCache.frontmatter.aliases
    pushAlternative(file.path, file.basename, file.alias)
    
  } else if (aliasType == "object" && file.frontmatter?.aliases.length ) {
    // Multiple aliases
    for (const alias of fileCache.frontmatter.aliases ) {
      file.alias = alias
      pushAlternative(file.path, file.basename, file.alias)
    }
  }
})

const destination = await tp.system.suggester(
  item => item.basename + 
         (item.alias != item.basename ? `\n↳ ${ item.alias }` : ""),
  alternatives,
  true,
  "Enter file",
  10);

if (destination)
  tR += `[[${ destination.path } | ${ destination.alias }]]`
_%>

```

As a sample image, I searched for “newa” in my test vault, and got this result:

 ![image](https://forum.obsidian.md/uploads/default/original/3X/b/1/b106c88b23a00899c6803bd1571081a3367ce34b.png)

As we can see in the image both the fuzzy matching, and the aliases works. (See files “221231 - New years eve” and “New file 1 → new alias”).

And choosing the latter of those it produces the link `[[tmp/new file 1.md | new alias]]`. Hope this helps!

( Now I just need to figure out how to create a new file link based upon this without having to trigger another `tp.system.prompt()` or similar, as I then can use this template to locate or create new forum response notes. 😃 )

---

_[View the full topic](https://forum.obsidian.md/t/use-aliases-with-templater-suggester/76244)._
