`import`

In `ftd`, one module/component can access code from another component by importing it. To import a module, use the following syntax:
use of import
-- import: 
Lang:
ftd
You can do following imports: - [Import `fastn`](import/#import-fastn) - [Import module from current package](import/#import-module-from-current-package) - [Import module from dependency package](import/#import-module-from-dependency-package) - [Import special modules](import/#import-special-modules) `ftd` also provides a way to define [import alias](import/#understanding-alias).

Import `fastn`

`fastn` provides a special module called `fastn`, which gives you access to useful package-related variables. You must have noticed that `FASTN.ftd` imports this module. To import the `fastn` module in your code, use the following syntax:
import `fastn`
-- import: fastn
Lang:
ftd
The special variables provided by this module are: - document-name: Returns a string representing the current [document's name](glossary/#document-name). - package-name: Returns `string` representing the package name. - home-url: Returns `string` representing the package's website address.

Import module from current package

Suppose you have a module called `bar.ftd` in your `fastn` package, named `my-package`, and you want to import it in another module called `foo.ftd`. To import the `bar` module in your `foo` module, use the following syntax:
In `foo.ftd`
-- import: my-package/bar
Lang:
ftd

Import module from dependency package

Suppose you want to import the `bar` module from a dependency package called `other-package` in `foo` module of your current package, `my-package`. To import the bar module in your foo module, use the following syntax:
In `foo.ftd`
-- import: other-package/bar
Lang:
ftd

Import special modules

The`fastn` package has a special module, `assets` importing which you get access to its variables. These variables contains the reference to the files or fonts defined in the package.
Import assets
-- import: my-package/assets
Lang:
ftd
The file referring variables are [foreign variables](foreign-variable), while, fonts are simple variable. For more information, please visit [assets](assets).

Understanding Alias

In `ftd`, an alias is an alternative name that can be used to refer to an imported module. Aliases can be helpful in making the code more concise and readable.

Defining Alias

To define an alias in ftd, we can use the as keyword when importing a module. For example, to create an alias `mn` for a module called `module-name`, we can write:
-- import: module-name as alias
Lang:
ftd
This allows us to refer to the imported module as `mn` instead of `module-name`.

`ftd` defined alias

`ftd` also defines aliases by itself, when we import a module without specifying an alias using the `as` keyword. In this case, the word after the last slash in the module path becomes the alias. For example:
-- import: some/path/to/module
Lang:
ftd
In this case, the alias would be `module`.

Advantages of Aliases

Aliases can be helpful in several ways: - **Abbreviation**: Aliases can be used to create shorter or more concise names for commonly used or long entities. - **Code readability**: Aliases can make code more readable and understandable by giving names to modules that more clearly convey their purpose or meaning. - **Refactoring**: When refactoring code, like changing the dependencies or imported modules. Aliases can be used to keep the original names in use while the code is being updated to use the new names, so the code continues to work while changes are being made. - **Reducing name collisions**: Aliases can help avoid naming collisions when importing multiple modules with similar or identical names. - **Compatibility**: Aliases can be used to maintain compatibility with legacy code or other systems that refer to entities by different names. This can make it easier to integrate with external packages or modules that use different naming conventions. Overall, aliases can help improve the clarity, readability, and maintainability of code, while also making it more efficient to write and easier to integrate with other systems.

Support `fastn`!

Enjoying `fastn`? Please consider giving us a star ⭐️ on [GitHub](https://github.com/fastn-stack/fastn) to show your support!
[⭐️](https://github.com/fastn-stack/fastn)

Getting Help

Have a question or need help? Visit our [GitHub Q&A discussion](https://github.com/fastn-stack/fastn/discussions/categories/q-a) to get answers and subscribe to it to stay tuned. Join our [Discord](https://discord.gg/a7eBUeutWD) channel and share your thoughts, suggestion, question etc. Connect with our [community](/community/)!
[💻️](/community/)

Found an issue?

If you find some issue, please visit our [GitHub issues](https://github.com/fastn-stack/fastn/issues) to tell us about it.

Quick links:

- [Install `fastn`](install/) - [Create `fastn` package](create-fastn-package/) - [Expander Crash Course](expander/) - [Syntax Highlighting in Sublime Text](/sublime/)

Join us

We welcome you to join our [Discord](https://discord.gg/a7eBUeutWD) community today. We are trying to create the language for human beings and we do not believe it would be possible without your support. We would love to hear from you.
Copyright © 2023 - [FifthTry.com](https://www.fifthtry.com/)