I am looking the way to have the result of this ruby template file:
ServerName 1.server.foo
knowing that if I run
$ facter -p fqdn
1.server.foo.internet.com
I would probably play with <%= #fqdn %> and .gsub?
server-id: <%= #fqdn %>.gsub(/.internet.com/, '')
The entire expression needs to be in the <%= %> tag, so try
server-id: <%= #fqdn.regsubst(/.internet.com/, '') %>
The template syntax is documented at https://puppet.com/docs/puppet/5.5/lang_template_erb.html with examples of expressions used in <%= %> tags.
I'd also note that ERB templates have been replaced by native Embedded Puppet EPP templates, so it may be better to convert now.
using EPP with regsubst it works!
server-id: <%= $facts[fqdn].regsubst(/.internet.com/, '') %>
Related
I am using Hygen to populate template files and want to print an array of strings eg.
[`'${item}'`]
but the single quotes are being converted to '
All other special characters are unaffected but single or doublequotes get converted so I'm not sure what's going on.
Turns out
<%= %>
tags in the template file escapes some characters, whereas...
<%- %>
does not!
I am trying to print a NodeJS object as simple json in EJS template file.
I am defining the object in NodeJs and trying to print it in EJS file like this:
<%= JSON.stringify(objName) %>
This is encoding double quotes (") is some format and giving me output like this:
{"_id":"5c3587b78ff1928c5124bf6d","name":"Sourabh Bajaj","role":10,"roleName":"InstituteAdmin","mobileNumber":"+919166677890","email":"sorbhb#gmail.com","mobileVerified":true,"emailVerified":true,"instituteId":"5c3586308ff1928c5124bf24","passwordResetKey":"","success":true,"errorCode":200};
If I don't stringify it, it give me [Object object] as output.
Found the answer. EJS template somehow encodes double quotes when you use <%= %>.
If you don't want that, use <%- %> tags instead.
In this block I'm need to replace substring http to https
{{ system.getBlock('info-product-carousel')|raw }}
I try to use replace like this:
|replace({'%http%': "https"})
But this construction don't work in my situation:
{{ system.getBlock('info-product-carousel')|raw|replace({'%http%': "https"})} }}
I somewhere was mistaken, but I don't no twig and couldn't find the solution by myself.
If I use <%= ENV['FOO'] %> in an erb template without setting an environment variable named FOO, then it resolves to an empty string.
Is it possible to force an error (index error, anything) at this point instead; evaluating to a string iff $FOO exists?
By default, groovy's SimpleTemplateEngine uses <% %> as the scriptlet container. How do I escape these characters if I want to print out <% %>?
Looks like it might be a bug
http://jira.codehaus.org/browse/GROOVY-399
The book I've red (which might be outdated) says that you need to have variable that contains <% and %> and then you need to output those variables.