Slim和Twig

时间:2016-04-29 21:30:12

标签: php html twig

我将文章存储在MySQL数据库的文本块中,然后将它们拉出并显示给用户。在“编辑文章”视图中,它显示具有正确换行符和间距的文章,但是当我向用户回显文章时,格式化消失...我已附加两个图像,代码如下。< / p>

编辑视图(正确):

{% extends 'templates/default.php' %}

{% block title %}Edit An Article{% endblock %}

{% block content %}
<article class="article">

    <header>
        <h2>Edit An Article</h2>
    </header>

    <footer>
        <p class="post-info">Complete this form to edit the article.</p>
    </footer>

    <form class="pure-form" name="edit_article" action="{{ base_url }}/admin/articles/e/{{ article_info.id }}" method="post" autocomplete="off" >
        <ul class="form" id="add_articles">
            <li>
                <label for="title">Article Title</label>
                <br />
                <input type="text" class="login-input" name="title" id="title" value="{{ article_info.title }}" placeholder="Title"><div style="color: #e01b37">{% if errors.first('title') %}Must be less than 50 characters long.{% elseif errors.first('article') %}Must be a unique title.{% endif %}</div>
            </li>
            <li>
                <label for="body">Body</label>
                <br />
                <textarea class="pure-input-1 autoExpand" name="body" id="body" placeholder="Body">{{ article_info.body }}</textarea><div style="color: #e01b37">{% if errors.first('body') %}A body is required.{% endif %}</div>
            </li>
            <li>
                <label for="home">Display the full article on the home page and to the public?</label>
                <br />
                <select name="home">
                    <option value="2">No</option>
                    <option {{ article_info.home }} value="1">Yes</option>
                </select>
            </li>
            <li>
                <br />
                <button class="pure-button" type="submit" name="Submit"><i class="fa fa-plus"></i>  Confirm Changes</button>
            </li>
        </ul>
    </form>
</article>
{% endblock %}

最终视图(不正确):

{% extends 'templates/default.php' %}

{% block title %}{{ article_info.label }}{% endblock %}

{% block content %}
    <article class="article">
        <header>
            <h2>{{article_info.title}}</h2>
        </header>

        <footer>
            <p class="post-info">Created By <a class="readMore" href="{{ base_url }}/u/{{ article_info.username }}">{{ article_info.username }}</a></p>
        </footer>

        <content>
            <p class="preview">{{ article_info.body }}</p>
            <p><a class="readMore" href="{{ urlFor('articles') }}">All Articles</a></p>
        </content>

    </article>

{% endblock %}

format example

1 个答案:

答案 0 :(得分:0)

{{ article_info.body }}更改为{{ article_info.body | nl2br | raw }}