{"action":"opened","issue":{"url":"https://api.github.com/repos/hexojs/hexo/issues/2059","repository_url":"https://api.github.com/repos/hexojs/hexo","labels_url":"https://api.github.com/repos/hexojs/hexo/issues/2059/labels{/name}","comments_url":"https://api.github.com/repos/hexojs/hexo/issues/2059/comments","events_url":"https://api.github.com/repos/hexojs/hexo/issues/2059/events","html_url":"https://github.com/hexojs/hexo/issues/2059","id":167398782,"number":2059,"title":"Question: Where should you run local variable API setup script?","user":{"login":"georgeedwards","id":10045919,"avatar_url":"https://avatars.githubusercontent.com/u/10045919?v=3","gravatar_id":"","url":"https://api.github.com/users/georgeedwards","html_url":"https://github.com/georgeedwards","followers_url":"https://api.github.com/users/georgeedwards/followers","following_url":"https://api.github.com/users/georgeedwards/following{/other_user}","gists_url":"https://api.github.com/users/georgeedwards/gists{/gist_id}","starred_url":"https://api.github.com/users/georgeedwards/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/georgeedwards/subscriptions","organizations_url":"https://api.github.com/users/georgeedwards/orgs","repos_url":"https://api.github.com/users/georgeedwards/repos","events_url":"https://api.github.com/users/georgeedwards/events{/privacy}","received_events_url":"https://api.github.com/users/georgeedwards/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-25T15:44:58Z","updated_at":"2016-07-25T15:44:58Z","closed_at":null,"body":"In my application, I want to be able to tailor my content by allowing the user to select either Javascript or Typescript. So I need to hold these values in a site wide variable. I then have a script which uses some custom block types, takes the content, checks the variable and decides whether to return the rendered markdown or null. \r\n\r\nSo I had something like this:\r\n\r\n```\r\nvar marked = require('marked');\r\n\r\nhexo.extend.tag.register('js', function (args, content) {\r\n  console.log(\"marked(content)\");\r\n  var result = marked('```bash\\n ' + content + '```');\r\n  if (hexo.locals.get('test_var') == \"js\") {\r\n    return result;\r\n  } else {\r\n    return null;\r\n  }\r\n}, { ends: true });\r\n```\r\n\r\nI would then have a function which called `hexo.locals.set('test_var', \"ts\");`, if the user selected a ui component. \r\n\r\nHowever, if I call `hexo.locals...` from an embedded script in the front end layout.ejs file, I get a:\r\n\r\n>hexo is not defined\r\n\r\nhow should I approach this problem?\r\n\r\n"}}
{"actor":{"display_login":"georgeedwards"}}