What's the correct way to use page variables in templates? #4881
-
Stuck trying to find the answer to this (undoubtedly simple) question: If I have defined a new HTML template, but want to use a relative link in an anchor tag. What is the right way to do this using template variables? Example: I have something like the following directory structure and some buttons in a template, which point to different markdown files in my
<!--- two example anchor tags in an HTML template, located in overrides and applied to the relevant md file's front matter -->
<a href="/dir_1/sub_dir_1/index.html" title="" class="md-button md-button--primary"> Page 1 </a>
<a href="/dir_1/sub_dir_2/index.html" title="" class="md-button md-button--primary"> Page 2 </a> I assume I should be pointing to either an HTML file (not a MD file) or the parent directory, given that these are index files. However, I also imagine there is some Jinja syntax that would be better. Just struggling to figure it out, and the options I have tried don't seem to work when running Thanks for any answers in advance and sorry for the basic question. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
I'm sorry, but I don't fully understand what you're trying to do to help you. Maybe provide a self contained example which I can run and attach it here + describe exactly what your desired behavior would be. |
Beta Was this translation helpful? Give feedback.
-
As always, thanks for the prompt reply @squidfunk. No worries, here's a minimal example (attached). The desired behaviour is that the two button links in the Also, it may seem odd (based on this minimal example) that I am trying to do this with an HTML template in the first place, but I aim to eventually build a more complicated template. |
Beta Was this translation helpful? Give feedback.
-
And, I've just figured it out using this minimal example. Sorry. Sometimes the basic setup is what's needed to troubleshoot things. I didn't realise that the relative links should not be based on where the template is located, but on where the actual page is located. Kind of obvious once you figure it out!! Thanks anyway. |
Beta Was this translation helpful? Give feedback.
And, I've just figured it out using this minimal example. Sorry. Sometimes the basic setup is what's needed to troubleshoot things. I didn't realise that the relative links should not be based on where the template is located, but on where the actual page is located.
Kind of obvious once you figure it out!!
Thanks anyway.