Skip to content

How get config from _config.yml in scripts? #4964

Discussion options

You must be logged in to vote

@gjssss

In hexo 6.x.x you can get the theme config values like the below way.

// themes/<your_theme>/scripts/example.js
function themeConfigConsoleLog() {
  console.log(this.config.theme_config);
}

// Please see: https://hexo.io/api/filter
hexo.extend.filter.register('after_init', themeConfigConsoleLog)

// Also you can use it in a template engin (e.g: EJS)
// https://hexo.io/docs/helpers
hexo.extend.helper.register('<helper_name>', themeConfigConsoleLog)

If you have a _theme.<your_theme>.yml.

// _theme.<your_theme>.yml
title: test

You can see theme config when start a server.

$ hexo server

INFO  Validating config
{ title: 'test' }
INFO  Start processing

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@gjssss
Comment options

@yoshinorin
Comment options

Answer selected by gjssss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants