解释String中的HTML标记

时间:2018-02-06 10:29:32

标签: twig

我在我的项目中使用Twig模板,并且我有一个WYSWYG编辑器来保存用户在数据库中想要的内容......

现在在我的模板部分中,我检索了这样的内容:grunt,当我查看我的页面时,结果是这样的:

{{ datas.post.getContent()}}

所以我尝试了原始版本或striptag或autoescape ......

<p>Hello, <em>how are you doing</em>?<    /p><p>I admit <strong>I am not fine</strong>, it's not working...</p>

但我尝试的一切都给了我这个结果

{% autoescape %} {{ datas.post.getContent()}} // {{ datas.post.getContent()|raw}} // {{ datas.post.getContent()|striptags}} {% endautoescape %}

我尝试将缓存环境设置为假......但没有任何事情发生...... 我想要这个结果:

  

你好,你好吗?我承认我不好,但事实并非如此   工作...

正确的方法是什么?

2 个答案:

答案 0 :(得分:0)

好吧,我的坏...... 我没有看到另一个开发者制作了htmlspecialchars功能...... 所以我首先在我的控制器中对其进行解码,然后使用const autowatched = process.env.npm_lifecycle_script.indexOf('--auto-watch') !== -1; module.exports = function (config) { var grep = require('karma-webpack-grep'); var testWebpackConfig = require('./webpack.test.js')({ env: 'test' }); var electronflags = autowatched ? ['--show'] : []; testWebpackConfig.plugins = (testWebpackConfig.plugins || []).concat(grep({ grep: config.grep, basePath: '', // same as basePath testContext: '../src' // same as require.context line in spec-bundle.js })); var configuration = { basePath: '', frameworks: ['jasmine'], exclude: [], client: { captureConsole: autowatched ? true : false, useIframe: false }, files: [ { pattern: './config/spec-bundle.js', watched: false }, { pattern: './src/assets/**/*', watched: false, included: false, served: true, nocache: false } ], proxies: { "/assets/": "/base/src/assets/" }, preprocessors: { './config/spec-bundle.js': autowatched ? ['webpack', 'electron', 'sourcemap'] : ['coverage', 'webpack', 'electron', 'sourcemap'] }, webpack: testWebpackConfig, webpackMiddleware: { noInfo: true, stats: { chunks: false } }, reporters: ['mocha'], port: 9876, colors: true, logLevel: autowatched ? config.LOG_INFO : config.LOG_WARN, autoWatch: false, browsers: ['ElectronDebugging'], customLaunchers: { ElectronDebugging: { base: 'Electron', flags: electronflags , }, }, singleRun: true }; if (!autowatched) { configuration.reporters.push('coverage'); configuration.coverageReporter = { type: 'in-memory' }; configuration.reporters.push('remap-coverage'); configuration.remapCoverageReporter = { 'text-summary': null, json: './coverage/coverage.json', html: './coverage/html' }; } else { // show console.log messages when debugging configuration.browserConsoleLogOptions = { level: 'log', terminal: true }; } config.set(configuration); }; 进行渲染(我可以删除autoescaping ...)

抱歉打扰......

答案 1 :(得分:-1)

可能您将转换后的数据保存在数据库中。检查保存的html的格式。 或者可能在传递数据之前查看你有某种htmlspecialchars。