0

I have a backend written in PHP, frontend with Twig templates and Vue components. I'm trying to pass data from my PHP controller into my Vue component, and I'm really not sure how to do this.

Let's say I have this in my controller:

    return $this->render('setting/setting.html.twig', [
  'title' => 'Your Etsy Settings',
  'tab' => 'Settings',
  'sub_title' => 'integrated with etsy',
  'message' => '',
  'settingForm' => $form->createView(),
  'storeId' => $store->getId()
]);

How can I access 'title' in my Vue component? Part of my template is Twig, and then I'm rendering my Vue components inside the Twig template.

1
  • 1
    You'd have to pass them to the Vue component (as a prop) within the Twig template. Something along the lines of <your-vue-component :title="{{ title }}">. (Sorry, I don't know Twig's syntax exactly, but that's the basic idea.) Commented Feb 13, 2019 at 19:20

1 Answer 1

1

Probably the problem is {{}} then you can swap

new Vue({
    delimiters: ['${', '}']
})

...

<your-vue-component :title="${ {{ title }} }">

https://v2.vuejs.org/v2/api/#delimiters

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.