duanpu1963 2014-02-13 20:22
浏览 206
已采纳

清除模板HTML代码块的方法,该代码块仅采用标题/内容参数,其中内容可能很大并且用新行填充

I am using Accordion (jQuery) on my school webserver. Currently, my coding-scheme uses PHP/HTML/CSS/Javascript. I started noticing an opportunity for automation/templating when writing the entries for the Accordion modules. I write the following code:

<h3>Title</h3>
<div class="nobg">
  <p class="nobg">
    <!-- Entry text -->
  </p>
</div>

so I am looking for pointers for the best way to template that code based on the following needs:

  • Adjustable parameters: Title, Content
  • When making new modules with a large content 'parameter', the creation of that parameter should maintain readability.

Since I am already on PHP, I was thinking maybe some sort of template function:

<? php accordion_entry("Title", "Entry Text" ?>

But the text is usually a lot of HTML: like the following:

<a href="EnablerIIG/GSM0107_full.pdf">PDF</a>
  <p>
    The release date is 2007 but the pinout seems to check out (I did some small verifications with my PCB). Also, the reference documents are all valid!
  </p>

I would like to write that HTML myself in the designated spot where the module will eventually manifest as a whole. Perhaps even cooler would be something like this:

<accordion-entry title="Title">
    <a href="EnablerIIG/GSM0107_full.pdf">PDF</a>
    <p>
      The release date is 2007 but the pinout seems to check out (I did some small verifications with my PCB). Also, the reference documents are all valid!
    </p>
</accordion-entry>

I have no idea how to get started creating such a mechanism, or if it's too much trouble to bother.

  • 写回答

2条回答 默认 最新

  • doujing4555 2014-02-13 20:53
    关注

    I found my temporary solution, until someone comes along with something better! Please review! I am no PHP Expert!! :D

    The PHP Function:

    <?php
    
    function accordionEntry($title, $entry)
    {
        echo '<h3>' . $title . '</h3>';
        echo '<div class="nobg">';
        echo '  <p class="nobg">';
        echo $entry;                //  <!-- Entry text -->
        echo '  </p>';
        echo '</div>';
    }
    
    ?>
    

    The PHP function call:

    <?php accordionEntry(
        "GSM0107IG001 - Integration Manual",
    
        '<a href="EnablerIIG/GSM0107_full.pdf">PDF</a>
        <p>
            The release date is 2007 but the pinout seems to check out (I did some small verifications with my PCB). Also, the reference documents are all valid!
        </p>');
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划