Global variables in MkDocs - html

I have a documentation project made with MkDocs. I would like to define global variables in the configuration file (mkdocs.yml) to be used in the markdown pages (*.md).
Reading this issue, it seems it can be done by including an extra configuration in the mkdocs.yml file, for example:
extra:
version: 1.0
... and then, use that variable in page for example as follows:
---> My version: {{ config.extra.version }}
I tried that, but unfortunately it is not working in my example (no variable substution):
Am I doing something wrong?
Is is possible to make this work?

No, this is not possible at this time.
You say that you "use that variable in page". I'm assuming you mean a "Markdown" page. At this time template variables are not available in the Markdown pages. The template engine is not even run against the Markdown. The output of the Markdown parser is one of the variables passed to the template. For a more detailed explanation of how that works, see my answer to How do you include flask/jinja2 code inside a markdown file?.
Specific to MkDocs, there is an open issue (#304) discussing adding a feature to support some limited templating within the Markdown pages, but it is scheduled for post-1.0, so its not a top priority at this time.

The given answer is out of date as this can be done with plugins like macros or markdownextradata as mentioned above except you would just reference {{ version }}.

As an update, it is possible to insert the variables from the extra slot in mkocs.yml, exactly as you describe.
To make this work, you need to install the markdownextradata plugin.

Related

In sphinx jinja2 template, get the path to current document

I'm building documentation with Sphinx and rST. The docs are internationalized and deployed to paths like this:
website.tld/en/index.html
website.tld/de/index.html
Now on each page I'd like to give a link to the same page in different languages. Current language is available as the language variable, and the list of all languages is explicitly added to the html_context and, thus, also available.
What I struggle with is the relative path to each document. Say, there's a source document at ./source/somepath/docname.rst. It builds into these:
website.tld/en/somepath/docname.html
website.tld/de/somepath/docname.html
In the Jinja2 template, how do I get the "somepath/docname.html" value?
Suddenly, I've found the solution in an answer to a related question:
{{ pagename }}
For a source document at ./source/somepath/docname.rst, the value of pagename is "somepath/docname", which is quite what I need.
Here's the documentation for this variable.

Difference between name.html.erb vs name.erb

What is the difference between name.html.erb vs name.erb?
In particular, are there any reasons why name.erb could be bad to use?
I understand that name.html.erb is the convention - this indicates a HTML template and ERB Engine. But I can't find information if are there any reasons not to use name.html.erb, but name.erb instead.
My new workplace asks me to use name.erb, so I want to know: might there be any problems with this?
In short, no, there won't be any problems. Erb files simply output text. In many cases the file extension is ignored by the reading app as the reading app reads/interprets the containing text and its syntax validity. As #taglia suggests, the file extensions are mostly a 'hint' for you and may also be used by the OS to select a default app to open the file with. See here for a more thorough explanation: Output Type for an ERB File
Rails convention dictates template files to include the extension of the output type and the name of the file should end with the .erb extension. As you mentioned, name.html.erb indicates an HTML template and ERB extension that allows any instance variables in your controller's index action to get passed into the template and used. Similarly, name.js.erb indicates a JavaScript template. See here under 'Conventions or Template Files': An Introduction to ERB Templating
ERB is just a templating language, it is not limited to HTML (you could have name.txt.erb, or name.js.erb). Removing html from the name is just going to make your life more difficult (assuming it works), because you won't be able to know what file you are dealing with unless you open it.

HTML in Jenkins job descriptions

I have two Jenkins instances running. An old (legacy) one at version 1.614 and a new one with 1.633.
In the old one it is possible to use HTML in the job description (it even does syntax highlighting editing it). The new one doesn't. HTML content is escaped and shown as plain text. I could not find a change in the release notes explaining this behavior. Is there a configuration that I'm missing?
In the Global security menu:
Select this value to display HTML:
For enabling it via config: you have to install the configuration as code (CASC) plugin (https://plugins.jenkins.io/configuration-as-code/) , and add the following entries to your config file(s - I guess, it is better to have multiple files for a better overview):
markupFormatter:
rawHtml:
disableSyntaxHighLighting: false
If you don't need highlighting, change it to true

How can I create PHP templates for PhpStorm with existing code inside?

I want to create a php Template in PhpStorm with has a comment block at the top with the usual info (author, creation date, class etc.) but also with a bunch of premade functions.
The purpose of this is that I want to make PHP Unit Class Template with the setup/teardown functions already coded, because these template are used for one project I don't expect they will change as the setups just set global which really should always be set up to make building the test easier (i.e. getting global scoped helpers).
I've tried creating the file templates however when I've copied the code into the template, any variable comes up as in input box when I go to create the file, which might be fine for me using but for someone who's using it for the first time they can screw up by filling in values for this-.
So I am wondering, how can I create a template in PhpStorm which has code in it?
You need to escape $ character which is used by Velocity template engine internally (has special meaning).
You can use ${DS} or \$ for that; so $this will become ${DS}this or \$this .
P.S. ${DS} is a safer choice overall as in some cases \$ may not work.
The official help page has it all explained: https://www.jetbrains.com/help/phpstorm/file-template-variables.html

Snippet with Custom Variables

I'd like to create a package containing a series of snippets that incorporate user-definable variables. For example, I'd like the user to be able to provide a value for a variable called HOSTNAME and have the snippets include that user's value.
The Sublime Text Unofficial Documentation explains:
Snippets have access to contextual information in the form of environment variables. Sublime Text automatically sets the values of the variables listed below.
You can also add your own variables to provide extra information. These custom variables are defined in .sublime-options files.
I've had no luck finding any information on the syntax for a .sublime-options file, however, and Sublime does not seem to try to read a file with that extension when I save it anywhere under the Packages directory. Is this a typo?
Using a .tmPreferences file seems to do what I'm looking for. Is this the only method of getting user-defined values into a snippet? Is it possible to use a .sublime-settings file?
The .sublime-options, actually, is the .sublime-settings. .sublime-options were the ST1 files and the docs got outdated, BUT you use the wrong link, you should always check and switch in the sidebar on the left to your version - ST2, ST3.
And to answer your question, you need to put the variables in .tmPreferences as may be seen here