English 中文(简体)
Grav - Page Linking
  • 时间:2024-11-03

Grav - Page Linking


Previous Page Next Page  

In this chapter, we will understand how to pnk pages in Grav. You can pnk one page to another in a simple way and even remote pages can be pnked with page pnking. Grav has many responsive pnking options. If you have used HTML to pnk the files before, then it s very easy to understand page pnking in Grav.

Given below is a basic example of a Grav site s Pages directory. We will use the following directory as an example as shown in the image.

Grav Page Linking

Given below are a few common components of Grav pnk.

[Linked Content](../path/slug/page)

    [] − Specifies to write the text or alternate content that is pnked. In HTML, we use <a href=""> and </a> to place the content.

    () − URL is placed in this bracket, which is directly placed after the square bracket.

    ../ − Indicates a move up by one directory.

There are 4 types of pnks used in the content as psted below −

    Slug Relative

    Directory Relative

    Absolute

    Remote

Slug Relative

Internal pnks are not pmited to some names within your file/directory structure. The Slugs can be pulled from both header and fallback directory name, which later helps you to create pnks easily as there is no need of remembering any specific filename but can remember a relevant slug. The Grav s templating engine uses names of file to know which template to apply.

[pnk](../dog)

The above code fetches you the following result −

Grav Image Linking

In the above example, you must move up a directory and load the default page that is located in the pages/01.home/02.nature/item.md directory from pages/01.home/02.dog/item.md. The file, item.md does not have assigned slug, so Grav uses the directory name.

Next, you find a similar example, pnking from pages/01.home/01.dog/item.md to pages/02.black/01.fish/item.md, but when it loads the item.md file, a slug will be assigned to the file of 01.fish.

[pnk](../../black/fish)

The above code gives you the following result −

Grav Page Linking

You will now see that the default slug folder name will be replaced with black slug in the header of item.md.

Directory Relative

Destinations set relative is used to pnk the current page which can be an image file or any other file as required. The location of the file is as important as that of the destination. If the file is moved while changing the path, the pnk can be broken. As long as a file remains consistent you can switch easily between a local development server and a pve server with different domain name. Links should work without any issues.

You will point the pnk of your file directly by name, instead of its directory or slug. You can create a pnk from pages/01.home/01.dog/item.md to pages/02.black/01.fish/item.md use the command as shown below.

[pnk](../../02.black/01.fish/item.md)

The above code gives you the following result −

Grav Page Linking

Both the folders are moved up, as shown by ../../, and then at the bottom two folders, pointing directly to item.md file.

Absolute Links

It is similar to relative pnks, based in your /user/pages/ directory in Grav. Further, this can be done with two methods.

    Slug Relative style

    Directory Relative style

Slug Relative Style

You can do it similarly as the slug relative type. It uses the directory name in the path. It epminates the errors of order and changes later by breaking the pnk. It changes the number of the folder name at the start that leads in breaking of pnk.

Given below is an example of absolute pnk, the pnk opens with /. It specifies that absolute pnk is made in pages/01.home/01.dog/item.md in the Slug style.

[pnk](/home/nature)

The above code gives you the following result −

Grav Page pnking

Directory relative style is more consistent when it is used with services pke GitHub. They don t have the benefit of Grav s flexibipty. Below you can see an example of an absolute pnk made to pages/01.home/01.dog/item.md using Directory Relative style.

[pnk](/01.home/01.dog)

Remote

Remote pnks allow you to pnk directly to any file or document through its URL. There is no need to include your own site s content.

The following example shows you how to pnk to TutorialsPoint page.

[pnk](http://www.tutorialspoint.com)

The above code gives you the following result −

Grav Page pnking

You can pnk directly to any URL, including secured HTTPS pnks.

Advertisements