wesort
June 29, 2022, 2:20pm
#1
I’m having trouble with a conditional not being recognised when deploying in production.
The Jekyll templating:
{% if jekyll.environment == 'production' %}
<meta name="robots" content="INDEX, FOLLOW">
{% else %}
<meta name='robots' content="noindex,nofollow" />
{% endif %}
netlify.toml
# Production context:
# All deploys from the main repository branch
[context.production]
JEKYLL_ENV="production"
# Branch deploys
[context.branch-deploy]
JEKYLL_ENV="dev"
Netlify recognises the production deployment
However, the final html isn’t as expected
Any ideas where I’m going wrong with this?
I have the same problem.
In toml:
[context.production.environment]
DATABASE_URL_ENV_VAR = "DATABASE_URL_PROD"
Then I have DATABASE_URL_PROD set in the UI.
Then I’m reading it in the function:
const handler = async (event: Event, context: Context) => {
console.log(process.env) // doesn't have the DATABASE_URL_ENV_VAR
How about using the built in read only CONTEXT variable?
Netlify builds, deploys, and hosts your frontend.
Learn how to get started, find examples, and access documentation for the modern web platform.
Another post that’s double posted in helpdesk as well as forums
The short answer is, variables defined in netlify.toml
are not accessible to serverless Functions.
wesort
July 7, 2022, 10:40am
#5
@hrishikesh - my initial question was not to do with serverless functions and I’ve not posted to helpdesk.
Any insight on where I’m using environment context incorrectly?
Hey @wesort ,
About the duplicate post, I was talking about @alexbezh , not you.
In your case, the problem is because, the variables should be used under context.production.environment
.
1 Like
wesort
July 15, 2022, 10:43am
#11
Thank you @hrishikesh - that’s working for me now.
Thanks for coming back and letting us know! Happy building!