0

I am trying to generate a sitemap, which works just fine if I do it in a standard xml file. The problem I am facing is that I need to generate a xml sitemap within twig file.

So i have this file: sitemap.xml.twig with this content:

{{ <?xml version="1.0" encoding="UTF-8"?> }}

{{ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> }}
    {{ <url> }}
        {{ <loc>http://www.example.com/</loc> }}
        {{ <lastmod>2005-01-01</lastmod> }}
        {{ <changefreq>monthly</changefreq> }}
        {{ <priority>0.8</priority> }}
    {{ </url> }}
{{ </urlset> }}

But I get an error: "message":"Unexpected token

how can i make xml go into twig...? sorry I am new to twig

1 Answer 1

1

{{ literal }} is the twig syntax for variable output, so you can't (and why should you?) use that to embrace your xml syntax. Simply write your xml as-is, and insert dynamic content by this twig syntax (and, of course, by {% literal %} for methods and language constructs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.