Skip to content
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

Global variables in Definitions #1027

Closed
alfaromartino opened this issue May 12, 2023 · 2 comments
Closed

Global variables in Definitions #1027

alfaromartino opened this issue May 12, 2023 · 2 comments

Comments

@alfaromartino
Copy link

Suppose that I have some variable defined in config.md, let's call it id. And now I want to use that variable when I define the title, in the block wrapped by +++. Is it possible? So far, Franklin says id doesn't exist.

My goal? I wanted to define an ordered list of files in config.m, and then use eachindex to give a number to each. Then, I wanted to add that number to title on each local page. But it seems that global variables are not allowed within +++?

Thanks!

@tlienart
Copy link
Owner

tlienart commented May 14, 2023

If you define a variable in config.md you can access it in local pages with globvar(:name_of_var) so e.g.

config.md:

+++
a = "hello from global"
b = 235
+++

page1.md:

+++
c = globvar(:b)
+++

This is `c`: {{c}}

Assuming you have something like <title>{{title}}</title> in your layout files, you could also have on page1.md:

+++
title = globvar(:a)
+++

and the title of that tab/page will be "hello from global".

I hope that gives you elements to do what you wish for.

Note: just in case, from your description it seems you might need to use fd_rpath on local pages i.e. locvar(:fd_rpath) this will return the relative path to the current file. You can test it by adding

Current relative path: **{{fd_rpath}}**

on pages and seeing what it shows.

(closing but feel free to reopen if you still have questions)

@alfaromartino
Copy link
Author

I'm not with my computer now, but it seems that it's what I was looking for!
Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants