I'm trying to reuse some server-side twig files in twigjs. I'd like to add a path function that basically maps FosJsRouting bundle generate function, since obviously a client-side renderer can't render server paths without that data.
I see the examples on how to extend Twig with a custom function, but I never actually get a Twig variable, I simply load the templates via this terrific loader.
What I have now is:
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);
let template = require('../templates/headlines_by_group.html.twig');
let html = template({Routing: Routing, project: project});
and the template contains
<a href="{{ Routing.generate('project_show', {id: project.id}) }}">{{ project.name }}</a>
What I want I for the template to simply contain the server-side twig:
<a href="{{ path('project_show', {id: project.id}) }}">{{ project.name }}</a>
And have the path function be mapped from the Routing above, from https://github.com/FriendsOfSymfony/FOSJsRoutingBundle
Twig.extendFunction("path", (route, params) =>
{
return Routing.generate(route, params);
});
Is it even possible? Having path() in twigjs templates would be amazing.
I'm trying to reuse some server-side twig files in twigjs. I'd like to add a path function that basically maps FosJsRouting bundle generate function, since obviously a client-side renderer can't render server paths without that data.
I see the examples on how to extend Twig with a custom function, but I never actually get a Twig variable, I simply load the templates via this terrific loader.
What I have now is:
and the template contains
What I want I for the template to simply contain the server-side twig:
And have the path function be mapped from the Routing above, from https://github.com/FriendsOfSymfony/FOSJsRoutingBundle
Is it even possible? Having path() in twigjs templates would be amazing.