2

I am using shopware (symfony twig) and got a small app from vue that i have to implement. I just want to pass an object with translated strings from the shop to use as the text in the component but i get only the object keys and the values are empty.

In the twig template I have:

{% set snippets = 
 {
 header: example.header|trans
 }
%}
<div id="app" snippet={{ snippets|json_encode() }}>
  <demo></demo>
</div>
<script>
 new Vue({
  components: {
   demo: Component
  }
 }).$mount('#app')
</script>

and in the vue component i got

 data() {
  let snippetSet = document.getElementById('app').getAttribute('snippet')
  return {
   snippet: snippetSet,
  }
 },
 mounted() {
  console.log(this.snippet);
 }

the output is {"header":""}

It is my first time using this stack so I am really thankful for any recommendation about how to reach my goal in maybe a different way.

1 Answer 1

3

You must pass a string to the trans function, right now you are trying to read a non existant variable.

This should work:

{% set snippets = 
 {
 header: "example.header"|trans
 }
%}
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.