3

I am using a plugin for Grav CMS in conjunction with symfony/twig to import a yaml file with the following contents:

sp:
  xyzsp:
    description: ''
    issuer: https://ssotest.com
    relay_state: "/"
    login_url: https://ssotest.com
    logout_url: https://ssotest.com/access/logout
    slo_url: ''
    metadata: >-
      <?xml version="1.0" encoding="UTF-8" standalone="yes"?><EntityDescriptor entityID="your_subdomain.com" xmlns="urn:oasis:names:tc:SAML:2.0:metadata"><SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="true" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"><NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress</NameIDFormat><AssertionConsumerService index="1" Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://accountname.com/access/saml"/></SPSSODescriptor></EntityDescriptor>
    sign_response: false
    sign_assertion: true
    encrypt_assertion: false
    profile:
      assertion: global
      nameid: global
      attribute: empty
      response: global
      signature: global

I am creating an array and then using yaml_emit to import the full YAML file:

{% autoescape 'html' %}
{{ arr2|yaml_emit}}
{% endautoescape %}

This works for the most part. However, on the web page, the imported file is rendered without the >- block chomping indicator for the 'metadata' field, so it is rendered as:

sp:
  xyzsp:
    description: ''
    issuer: https://ssotest.com
    relay_state: /
    login_url: https://ssotest.com
    logout_url: https://ssotest.com/access/logout
    slo_url: ''
    metadata: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><EntityDescriptor entityID="your_subdomain.com" xmlns="urn:oasis:names:tc:SAML:2.0:metadata"><SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="true" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"><NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress</NameIDFormat><AssertionConsumerService index="1" Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://accountname.com/access/saml"/></SPSSODescriptor></EntityDescriptor>
    sign_response: false
    sign_assertion: true
    encrypt_assertion: false
    profile:
      assertion: global
      nameid: global
      attribute: empty
      response: global
      signature: global

How can I ensure the block chomping indicator is not removed?

KoreMike
  • 91
  • 7
  • How is the filter `yaml_emit` added to your project? I can't find it mentioned in the grav source. – Yoshi Nov 21 '17 at 13:44
  • yaml_emit is just a basic php function http://php.net/manual/en/function.yaml-emit.php – KoreMike Nov 21 '17 at 15:17
  • Well true, but still the filter needs to be set up in some way, so that twig actually recognized it as a valid filter. I'm asking because with the symfony yaml component you could try using the [forth parameter](https://symfony.com/doc/current/components/yaml.html#dumping-multi-line-literal-blocks). If it's actually the pecl function which is called, then you need to evaluate if that function can produce the output you want, and whether you can pass the then required options to it when using the twig filter. – Yoshi Nov 21 '17 at 16:48
  • Ah ok. So I need to set up a custom twig filter and make use of DUMP_MULTI_LINE_LITERAL_BLOCK. I will have to look into this – KoreMike Nov 21 '17 at 17:10

0 Answers0