十九、文章内容展示页面设计


前面已经对整个网站的布局做了周密的准备,下面就是最关键内容的展示了,完成了这一部分网站也就基本搞成了。本节我们把文章内容展示部分完成。

请尊重原创,转载请注明来源网站www.shareditor.com以及原始链接地址

修改controller

 

修改src/AppBundle/Controller/BlogController.php,把BlogController类的showAction改成:

    public function showAction($blogId)
    {
        $this->blogPostRepository = $this->getDoctrine()->getRepository('AppBundle:BlogPost');
        return $this->render('blog/show.html.twig', array('blogpost' => $this->blogPostRepository->find($blogId)));
    }

解释一下

$blogId是BlogPost的id号,用来在url中传入参数,后面会通过路由配置来对应。

render函数通过参数传入的$this->blogPostRepository->find($blogId)是通过BlogPost这个model获取id为$blogId的文章的BlogPost实例

 

修改模板

 

修改app/Resources/views/blog/show.html.twig,把内容清掉并改成:

{% extends "base.html.twig" %}

{% block body %}

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-xs-1"></div>
        <div class="col-sm-6 col-xs-10">
            <div class="row">
                <h1>{{ blogpost.title }}</h1>
            </div>
            <div class="row">
                <a class="btn btn-info btn-xs" href="{{ path('blog_list', {'subjectId':blogpost.subject.id}) }}">
                    {{ blogpost.subject.name }}
                </a>
                <a class="btn btn-success btn-xs" href="{{ path('blog_list', {'subjectId':blogpost.subject.id}) }}">
                    {{ blogpost.category.name }}
                </a>
                <small>发表于 {{ blogpost.createTimeStr }}</small>
            </div>

            <div class="row">
                <hr/>
            </div>
            <div class="row">
                <div class="row">
                    <div class="col-sm-12 col-xs-12">
                        <img style="width: 100%; height: 100%;" src="/uploads/media/default/0001/01/thumb_{{ blogpost.image.id }}_default_big.{{ blogpost.image.extension }}">
                    </div>
                </div>
                <br/>
                {{ blogpost.body|raw }}
            </div>
        </div>
        <div class="col-sm-3 col-xs-1"></div>
    </div>
</div>

{% endblock %}

配置路由

请尊重原创,转载请注明来源网站www.shareditor.com以及原始链接地址

修改app/config/routing.yml,把之前写过的:

blog_show:
    path:     /blogshow/
    defaults: { _controller: AppBundle:Blog:show }

改成:

blog_show:
    path:     /blogshow/{blogId}
    defaults: { _controller: AppBundle:Blog:show }

 

打开博客列表页,点击一篇文章标题,看下效果吧

总结

至此,我们的网站内容已经达到可以发布上线的状态了,方法可以参考前面章节讲过的服务器那些事,你可以申请一个阿里云服务器,注册个域名,部署上去,就像我的网站www.shareditor.com一样,以后只需要在后台管理管理文章就行了

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
XHTML 40个例子显示的内容一样,通过CSS实现不一样的布局效果, 是学习div + css排版的绝佳教程.body标签内的内容如下: Header 1) Content here. column long long column very long fill fill fill long text text column text silly very make long very fill silly make make long make text fill very long text column silly silly very column long very column filler fill long make filler long silly very long silly silly silly long filler make column filler make silly long long fill very. very make make fill silly long long filler column long make silly silly column filler fill fill very filler text fill filler column make fill make text very make make very fill fill long make very filler column very long very filler silly very make filler silly make make column column fill long make long text very make long fill column make text very silly column filler silly text fill text filler filler filler make make make make text filler fill column filler make silly make text text fill make very filler column very column text long column make silly long text filler silly very very very long filler fill very fill silly very make make filler text filler text make silly text text long fill fill make text fill long text very silly long long filler filler fill silly long make column make silly long column long make very 2) Navigation here. long long fill filler very fill column column silly filler very filler fill fill filler text fill very silly fill text filler silly silly filler fill very make fill column text column very very column fill fill very silly column silly silly fill fill long filler 3) More stuff here. very text make long silly make text very very text make long filler very make column make silly column fill silly column long make silly filler column filler silly long long column fill silly column very Here it goes the footer
好的,我可以为您提供一个简单的纯前端搜索栏的设计,实现搜索功能,具体如下: 1. 在页面上添加一个搜索框和一个搜索按钮。 2. 使用 JavaScript 监听搜索按钮的点击事件。 3. 当用户点击搜索按钮时,获取搜索框中的关键字。 4. 遍历页面中需要搜索的内容,比如文章标题、文章内容、标签等。 5. 对每个需要搜索的内容进行关键字匹配,如果匹配成功,则将该内容显示在搜索结果区域。 6. 如果没有搜索到任何内容,可以显示一个提示信息。 下面是一个简单的示例代码: HTML 代码: ``` <input type="text" id="search-input"> <button id="search-btn">搜索</button> <div id="search-results"></div> ``` JavaScript 代码: ``` // 监听搜索按钮的点击事件 document.getElementById('search-btn').addEventListener('click', function() { // 获取搜索框中的关键字 var keyword = document.getElementById('search-input').value; var results = document.getElementById('search-results'); results.innerHTML = ''; // 遍历页面中需要搜索的内容 var contents = document.querySelectorAll('.searchable'); for (var i = 0; i < contents.length; i++) { var content = contents[i].textContent; // 对每个需要搜索的内容进行关键字匹配 if (content.indexOf(keyword) !== -1) { // 如果匹配成功,则将该内容显示在搜索结果区域 var div = document.createElement('div'); div.textContent = content; results.appendChild(div); } } // 如果没有搜索到任何内容,显示一个提示信息 if (results.children.length === 0) { var div = document.createElement('div'); div.textContent = '没有搜索到任何内容'; results.appendChild(div); } }); ``` 在这个示例中,我们通过监听搜索按钮的点击事件,获取搜索框中的关键字,然后遍历页面中需要搜索的内容,对每个需要搜索的内容进行关键字匹配,如果匹配成功,则将该内容显示在搜索结果区域。如果没有搜索到任何内容,则显示一个提示信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值