-
Notifications
You must be signed in to change notification settings - Fork 141
Add importing variables from other files #891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0d70ce2
3c5831e
b82da4a
9ddae9a
d9d2d66
2c0a12e
3fff4fc
75c9d29
11cae4a
92065f6
fbb5120
199aa3c
e6883a7
18f9bcc
5b4273d
c3ed3fa
9b1a5b1
8fef8fc
3b02e65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,6 +103,72 @@ You can specify a default value for a variable, which is displayed when the vari | |
|
|
||
| Note: These variables will not be applied to [`<include>` files]({{ baseUrl }}/userGuide/reusingContents.html#the-include-tag). Additionally, global variables (`_markbind/variables.md`) will take precedence over any page variables. *See also: [Specifying Variables in an `<include>`]({{ baseUrl }}/userGuide/reusingContents.html#specifying-variables-in-an-include)*. | ||
|
|
||
| ### Importing Variables | ||
|
|
||
| **You can access [page variables](#page-variables) from another page by importing them.** | ||
|
|
||
|
|
||
| {{ icon_example }} Importing specific variables from `person.md` into `coverpage.md`: | ||
| `person.md`: | ||
| ```html | ||
| <variable name="address">123 Sun Avenue</variable> | ||
| <variable name="name">Mark</variable> | ||
| <variable name="phone">123456789</variable> | ||
| ``` | ||
|
|
||
| `coverpage.md`: | ||
|
|
||
| ```html | ||
| <import address name from="person.md"/> | ||
| ``` | ||
|
|
||
| will allow you to access the variables as per normal: <code>{<span></span>{address}}</code>, <code>{<span></span>{name}}</code>, <code>{<span></span>{phone}}</code>. | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider this structure (to be consistent with the rest of the documentation) i.e., abstract explanation followed by concrete example:
|
||
| --- | ||
|
|
||
| **When importing all variables, you should attach a _namespace_** to the imported variables using an `as` attributes. | ||
|
|
||
|
|
||
| {{ icon_example }}: | ||
| `coverpage.md`: | ||
| ```html | ||
| <import from="page.md" as="details"/> | ||
| ``` | ||
|
|
||
| | Detail | How to access | ||
| | :------------- |:------------- | ||
| | address | <code>{<span></span>{details.address}}</code> | ||
| | name | <code>{<span></span>{details.<span></span>name}}</code> | ||
| | phone | <code>{<span></span>{details.phone}}</code> | ||
|
|
||
| This way, ***all*** variables in `page.md` are accessible via <code>{<span></span>{details.<variable_name>}}</code>. | ||
|
|
||
| Note that in this case, `details` is treated as the variable name and so is subject to the same rules as other variables, such as global variables taking precedence, and multiple imports to the same namespace being impossible: | ||
|
|
||
| ```html | ||
| <import from="title.md" as="book"/> | ||
| <import from="index.md" as="book"/> | ||
| ``` | ||
|
|
||
| In this case, all the variables in `title.md` are not accessible, as they are overwritten with the variables from `index.md`. | ||
|
|
||
| <box type="important"> | ||
|
|
||
| Note that global variables (`_markbind/variables.md`) and [page variables](#page-variables) will take precedence over any imported variables. | ||
|
|
||
| While you can mix the two syntaxes for importing page variables, it may get confusing: | ||
| ```html | ||
| <import address name from="page.md" as="details"/> | ||
| ``` | ||
|
|
||
| This may seem like it will import *only* `address` and `name` from `page.md` and storing them in the namespace `details`. | ||
|
|
||
| However, this is a combination of *both* syntaxes above, and thus this will allow you to: | ||
|
|
||
| - access `address` and `name` (but NOT `phone`) with <code>{<span></span>{address}}</code> and <code>{<span></span>{name}}</code> | ||
| - access `address`, `name`, and `phone` with <code>{<span></span>{details.address}}</code>, <code>{<span></span>{details.<span></span>name}}</code>, and <code>{<span></span>{details.phone}}</code> | ||
|
|
||
| </box> | ||
|
|
||
| ### Variables: Tips and Tricks | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could collapse this by directly using it in
coverpage.md, saves some words.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think i'll keep it as it is, the change doesn't look very nice.