0

I have a Vue code but I need to show a link in twig:

<template>
<div class="col t-blk text-center d-flex justify-content-around">                                                       
<a class="btn btn-primary btn-md border-r-0 d-table py-2 px-4" href="{{path('corpasesoria')}}">Con Asesor</a>
<a class="btn btn-primary btn-md border-r-0 d-table py-2 px-4" id="step01-tab" data-toggle="tab" href="#step01" role="tab" aria-controls="step01" aria-selected="false">Sin Asesor</a>
</div>
</template>

But when compiling webpack it shows an error in the link of twig and can not be advanced.

This is the error:

ERROR  Failed to compile with 1 errors                                                                     00:58:12

 error  in ./assets/components/Corporativo/Corporativo.vue?vue&type=template&id=270a4b6a&scoped=true&

Module Error (from ./node_modules/vue-loader/lib/loaders/templateLoader.js):
(Emitted value instead of an instance of Error) 

  Errors compiling template:

  href="{{path('corpasesoria')}}": Interpolation inside attributes has been removed. Use v-bind or the colon shorthand instead. For example, instead of <div id="{{ val }}">, use <div :id="val">.

  15 |                                                                                          <div class="row">
  16 |                                                                                                  <div class="col t-blk text-center d-flex justify-content-around">
  17 |                                                                                                          <a class="btn btn-primary btn-md border-r-0 d-table py-2 px-4" href="{{path('corpasesoria')}}">Con Asesor</a>
     |                                                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  18 |                                                                                                          <a class="btn btn-primary btn-md border-r-0 d-table py-2 px-4" id="step01-tab" data-toggle="tab" href="#step01" role="tab" aria-controls="step01" aria-selected="false">Sin Asesor</a>
  19 |                                                                           

Do you have any idea?

juanitourquiza
  • 2,097
  • 1
  • 30
  • 52
  • What is the error? – DarkBee Jun 12 '19 at 05:50
  • This is the error: href="{{path('corpasesoria')}}": Interpolation inside attributes has been removed. Use v-bind or the colon shorthand instead. For example, instead of
    , use
    .
    – juanitourquiza Jun 12 '19 at 06:01
  • Possible duplicate of [Conflict on Template of Twig and Vue.js](https://stackoverflow.com/questions/31480612/conflict-on-template-of-twig-and-vue-js) – DarkBee Jun 12 '19 at 06:03

3 Answers3

1

Here is an example

import RoutingData from '../../../../dist/js/fos_js_routes';

import Routing from 'fos-routing';

Routing.setData(RoutingData); export default Routing;

slmder_h
  • 201
  • 1
  • 4
  • Now . I configure all but this is the error: "Error: "The route "corpasesoria" does not exist."" In vuejs this is the code: methods : { conAsesor: function (event) { alert('Hello !') Routing.generate('corpasesoria'); }} What is the problem? – juanitourquiza Jun 14 '19 at 17:56
  • You need to dump your routes every time you add new route as described https://symfony.com/doc/master/bundles/FOSJsRoutingBundle/usage.html – slmder_h Jun 14 '19 at 17:59
  • yes, this is the route in my controller: /** * @Route("/corporativo/asesoria", * options = { "expose" = true }, * name = "corpasesoria", * ) */ What is the problem?? – juanitourquiza Jun 14 '19 at 18:10
  • 1
    Read documentation https://symfony.com/doc/master/bundles/FOSJsRoutingBundle/usage.html. And dump your routes – slmder_h Jun 14 '19 at 18:16
  • Thanks. Now all work perfect. I'm going to correct the answer – juanitourquiza Jun 18 '19 at 14:15
0

Thanks to the help of slmder-h First you need to install: npmjs.com/package/fos-routing

npm install fos-routing --save

Then you need to read the symfony documentation: https://symfony.com/doc/master/bundles/FOSJsRoutingBundle/usage.html

After in the terminal

# Symfony Flex
bin/console fos:js-routing:dump --format=json --target=public/js/fos_js_routes.json

Inside the file .vue or .js

const routes = require ('../../ public / js / fos_js_routes.json');
import Routing from '../../vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js';

Routing.setRoutingData (routes);
Routing.generate ('asesoriajson');

Finally the Controller:

/**
 * @Route("/corporativo/asesoriajson",
 *     options = { "expose" = true },
 *     name = "asesoriajson",
 *       
 * )
 */
 public function asesoriajson(Request $request, SendMail $Sendmail)
 {
    $response = array();
    $response['type'] = null;
    $response['title'] = null;
    $response['message'] = null;

    $response['type'] = 'success';
    $response['title'] = 'Success';
    $response['message'] = 'Usted decidio utilizar un asesor'; 
    return new JsonResponse($response, 200);                    
}
juanitourquiza
  • 2,097
  • 1
  • 30
  • 52
0

You ca try to use fosjsrouring bundle to generate links inside js https://symfony.com/doc/master/bundles/FOSJsRoutingBundle/index.html

slmder_h
  • 201
  • 1
  • 4