app/template/default/Block/news.twig line 1

Open in your IDE?
  1. {#
  2. This file is part of EC-CUBE
  3. Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  4. http://www.ec-cube.co.jp/
  5. For the full copyright and license information, please view the LICENSE
  6. file that was distributed with this source code.
  7. #}
  8. {% set NewsList = repository('Eccube\\Entity\\News').getList() %}
  9. {% block javascript %}
  10. <script>
  11.   $(function () {
  12.     $('.news__list').each(function () {
  13.       var listLength = $(this).find('.news__item').length;
  14.       if (listLength > 5) {
  15.         $(this).find('.news__item:gt(4)').each(function () {
  16.           $(this).hide();
  17.         });
  18.         $(this).append('<a id="news_readmore" class="ec-inlineBtn--top">{{ 'more'|trans }}</a>');
  19.         var dispNum = 5;
  20.         $(this).find('#news_readmore').click(function () {
  21.           dispNum += 5;
  22.           $(this).parent().find('.news__item:lt(' + dispNum + ')').show();
  23.           if (dispNum >= listLength) {
  24.             $(this).hide();
  25.           }
  26.         })
  27.       }
  28.     });
  29.     $('.news__item-heading').on('click', function () {
  30.       $newsItem = $(this).parent('.news__item');
  31.       $newsDescription = $newsItem.children('.news__item-desc');
  32.       if ($newsDescription.css('display') == 'none') {
  33.         $newsItem.addClass('is-active');
  34.         $newsDescription.slideDown(300);
  35.       } else {
  36.         $newsItem.removeClass('is-active');
  37.         $newsDescription.slideUp(300);
  38.       }
  39.       return false;
  40.     });
  41.   });
  42. </script>
  43. {% endblock %}
  44. <section class="news">
  45.   <div class="inner">
  46.     <h2 class="section__heading">News<span class="section__sub-heading">お知らせ</span></h2>
  47.     <ul class="news__list">
  48.       {% for News in NewsList %}
  49.       <li class="news__item">
  50.         <div class="news__item-heading">
  51.           <p class="news__item-date">
  52.             {{ News.publish_date|date_day }}
  53.           </p>
  54.           <div class="news__item-column">
  55.             <div class="news__item-title">
  56.               {{ News.title }}
  57.             </div>
  58.             {% if News.description or News.url %}
  59.             <div class="news__item-close"></div>
  60.             {% endif %}
  61.           </div>
  62.         </div>
  63.         <p class="news__item-desc">
  64.           {{ News.description|raw|nl2br }}
  65.           {% if News.url %}
  66.           <br>
  67.           <a href="{{ News.url }}" {% if News.link_method=='1' %}target="_blank" {% endif %}>{{ '詳しくはこちら'|trans }}</a>
  68.           {% endif %}
  69.         </p>
  70.       </li>
  71.       {% endfor %}
  72.     </ul>
  73.   </div>
  74. </section>