title: How to use Thymeleaf to process YAML files?
body: <p>I'm trying to process YAML files using Thymeleaf. A sample file is given below:</p>
  
  <pre><code>apiVersion: v1
  kind: Service
  metadata:
    name: [[${app['name']}]]
    labels:
      app: [[${app['name']}]]
  spec:
    type: NodePort
    ports:
    - port: 80
      protocol: TCP
      name: http
    - port: 443
      protocol: TCP
      name: https
    selector:
      app: nginx
  </code></pre>
  
  <p>The value <code>app.name</code> comes from another YAML file that I parse at runtime.</p>
  
  <p>What I've tried so far:</p>
  
  <ol>
  <li><p>Creating a <code>MessageSource</code> with <code>Properties</code></p>
  
  <pre><code>TemplateEngine templateEngine = new TemplateEngine();
  templateEngine.setTemplateResolver(templateResolver);
  StandardMessageResolver messageResolver = new StandardMessageResolver();
  messageResolver.setDefaultMessages(props); // contains app.name
  templateEngine.setMessageResolver(messageResolver);
  </code></pre></li>
  <li><p>Setting a variable in the context</p>
  
  <pre><code>map.put("app.name", "test");
  context.setVariables(map); // contains app.name
  </code></pre></li>
  </ol>
  
  <p>But I keep getting the error:</p>
  
  <pre><code>Exception evaluating OGNL expression: "app['name']
  ...
  Caused by: ognl.OgnlException: source is null for getProperty(null, "name")
  </code></pre>
  
  <p>Using Thymeleaf 3.0.3.RELEASE. I'm using Spring and not using Spring, in the sense that the <code>spring-boot-starter-thymeleaf</code> brings in so much baggage mostly needed for HTML, I decided to just instantiate the template resolver and engine myself. It seems like people rarely process TEXT using Thymeleaf; all the examples I came across are HTML.</p>
  
  <p>I'd also like to know how to include a fragment of YAML in my templates.</p>
  
  <p><strong>Edit</strong>:
  Thanks to @Metroids, I got it working. Here's the <a href="https://github.com/asarkar/spring/tree/master/template-resolver" rel="nofollow noreferrer">link</a> to my sample app in case someone else has a similar problem.</p>