dstnlhhv791576 2015-07-27 08:35
浏览 41

如果唯一的优先事项是更容易更改布局,那么模板是否有帮助?

At the moment I have a website deployed using spaghetti coding - the PHP is intermingled through the HTML etc.

Each time there is a requirement to change anything significant with the layout, there is quite a big task to modify 100's of files to add / remove HTML, add/change classes and so on.

I started looking into templating and frameworks to try and make it easier as the theory is you separate presentation from logic which sounded ideal.

However upon further investigation I am struggling to see the benefit in this use case (I can see other benefits like cleaner code, easier for other developers to understand, possibility of designers being able to change layouts without involving developers and so on)

For example, today I have 200 files containing something like this:

<div class="outer">
    <div class="inner">
        <?php print $output; ?>
    </div>
</div>

From what I have read, should I deploy templating I would end up with something like:

<div class="outer">
    <div class="inner">
        {output}
    </div>
</div>

How does this make it any easier for me to change anything to do with the layout or presentation? I still have 200 files each containing HTML which need to be changed and instead of "PHP" I have placeholders.

However, if I want to add / remove a DIV or change a class, for example, I still need to do this manually in x files or use a search/replace etc.

Is there any easier way to achieve what I need to do?

  • 写回答

1条回答 默认 最新

  • douduan5073 2015-07-27 08:42
    关注

    You're actually already using a kind of templating - doing this will not make your code easier to adjust.

    The question is why do you need to change 200 files for a single layout change? Why don't you seperate this layout code (if it's the same) to a seperate file and include that file in your view so you'll only have to change 1 file when part of that layout changes? That's much more useful than just changing some syntax, which you clearly don't need here.

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用