将树枝与 react.js 集成 [英] Integrating twig with react.js

查看:31
本文介绍了将树枝与 react.js 集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地用 php symphony 和它的 twig 模板系统构建了一个 web 应用程序,但现在需求发生了变化,我必须使用 node react.js.我已经阅读了一些关于 react.js 的文档,但我仍然迷失在我严格的时间范围内的最佳方法.任何关于我如何安全快速地做到这一点的帮助都值得赞赏,即使是在高级阶段.有人如何在这样的模板中实现 react.js?

I have successfully built a webapp with php symphony and its twig template system, but now requirement has changed, and I have to make use of node react.js. I have read a handful of documentation on react.js but I am still lost on the best approach for my strict timeframe. Any help on how I can do this safely and quickly is appreciated, even in advanced. How can someone implement react.js in a template like this?

{% extends 'admin/base.html.twig' %}
{% block content %}
Fill This form
{{ form(form, {'attr': {'novalidate': 'novalidate'}}) }}
{{ form_start(form) }}
{{ form_widget(form) }}
    <input type="hidden" name="token" value="{{ csrf_token('action') }}" />
{{ form_end(form) }}
{% endblock %}

编辑由于我的项目的大小,在 React 中重新启动表单、表格和其他内容需要几个月的时间......所以我让我的 Symphony 应用程序将表单和表格 html 作为 JSON 字符串返回,并且我在 React 中处理表单就像 JADE 内容一样... 我希望这不会暴露安全威胁,我也在问它是否太蹩脚.谢谢.

EDIT Due to the size of my project, restarting form, table and others in react will take months... So I make my symphony app to return the forms and tables html as JSON string and I process the forms in React as if JADE content... I hope this will not surface security threat and I am also asking if it is not too lame. Thanks.

推荐答案

简单地说,您无法快速完成.React 是一个前端 JS 框架.Twig 是一个前端模板引擎.虽然可以让它们一起工作,但从这种立场来处理您的项目是没有意义的.一起使用 Twig 和 React 类似于将螺丝刀放入螺丝中,然后用锤子敲打.

Simply put you can't do it quickly. React is a front-end JS framework. Twig is a front-end templating engine. While it is possible to make them work together it doesn't make sense to approach your project from this stance. Using Twig and React together is akin to placing a screwdriver in a screw and then beating on it with a hammer.

用 React 完全取代你的 Twig 使用会更有意义.

It would make more sense to replace your Twig usage entirely with React.

这篇关于将树枝与 react.js 集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆