# Templater: navigation links between notes
*This script for [Obsidian.md](https://obsidian.md)'s [Templater](https://github.com/SilentVoid13/Templater) plugin generates links between documents in the same directory, excluding the note with the same name as the containing folder, for use with the [Waypoint](https://github.com/IdreesInc/Waypoint) plugin. With a keyboard shortcut, it works great.*
Este script para el plugin [Templater](https://github.com/SilentVoid13/Templater) de [Obsidian.md](https://obsidian.md) genera enlaces entre documentos en la misma directory, excluyendo la nota que lleva el mismo nombre de la carpeta contenedora, para usar con el plugin [Waypoint](https://github.com/IdreesInc/Waypoint). Con un atajo de teclado, funciona de maravilla.
> [!example]
> ![[../../Verbarium/En el mundo de las cenizas/En el límite del grito del polvo|En el límite del grito del polvo]]
```javascript
<%*
const currentFile = this.app.workspace.getActiveFile();
const currentFolderPath = currentFile.parent.path;
const folderName = currentFile.parent.name;
const files = this.app.vault.getMarkdownFiles().filter(file =>
file.parent.path === currentFolderPath &&
file.basename !== folderName); // Excluir el archivo con el mismo nombre que la carpeta
// Ordenar archivos por nombre
files.sort((a, b) => a.basename.localeCompare(b.basename));
const currentFileIndex = files.findIndex(file => file.path === currentFile.path);
const nextFile = (currentFileIndex + 1 < files.length) ? files[currentFileIndex + 1] : null;
const previousFile = (currentFileIndex - 1 >= 0) ? files[currentFileIndex - 1] : null;
if (previousFile) {
const previousFileName = previousFile.basename;
tR += `[[${previousFileName}]] ← Precedente\n`;
} else {
tR += `Inicio de la serie\n`;
}
if (nextFile) {
const nextFileName = nextFile.basename;
tR += `Siguiente → [[${nextFileName}]]`;
} else {
tR += `Fin de la serie`;
}
%>
```
*This is the same code adapted to include any note in the folder:*
Este es el mismo código adaptado para incluir cualquier nota en la carpeta:
```javascript
<%*
const currentFile = this.app.workspace.getActiveFile();
const currentFolderPath = currentFile.parent.path;
const files = this.app.vault.getMarkdownFiles().filter(file => file.parent.path === currentFolderPath);
// Ordenar archivos por nombre
files.sort((a, b) => a.basename.localeCompare(b.basename));
const currentFileIndex = files.findIndex(file => file.path === currentFile.path);
const nextFile = (currentFileIndex + 1 < files.length) ? files[currentFileIndex + 1] : null;
const previousFile = (currentFileIndex - 1 >= 0) ? files[currentFileIndex - 1] : null;
if (previousFile) {
const previousFileName = previousFile.basename;
tR += `[[${previousFileName}]] <- Precedente\n`;
} else {
tR += `Inicio de la serie\n`;
}
if (nextFile) {
const nextFileName = nextFile.basename;
tR += `Siguiente -> [[${nextFileName}]]`;
} else {
tR += `Fin de la serie`;
}
%>
```
#obsidian #templater #code
Not found
This page does not exist