首页 > 解决方案 > 在 OctoberCMS 中将树枝可变数据传递给 php 代码块

问题描述

我正在尝试从树枝循环生成的图像中读取 exif 图像数据。我正在尝试将 {{image}} 变量传递给 PHP 函数 onEnd ()。所以我的问题是如何访问 PHP onEnd() 函数中的 {{image}} 变量。

前端树枝

      {% for image in gallery %}

         {% set path = '/storage/app/media' %}
         {% set gallerySlug = record.gallery_folder %}
         {% set tilda = '/' %}
         {% set combinedLink = path ~ gallerySlug ~ tilda ~ image %}

           {% set link = path ~ image %}
                        
           <div class="grid-item wow fadeInUp" data-wow-duration="1s" data-wow-delay="0s" data-tilt data-tilt-speed="250" data-tilt-max="5" data-tilt-perspective="250">
             <a href="{{combinedLink}}" target="_blank"><img src="{{combinedLink | resize(1000)}}" alt="Camera: {{path}}"/></a>
           </div>
           
     {% endfor %}

PHP

  function onEnd () {     
   
    $frontId = $this->components['builderDetails']->record->id;

    $this["galleryLink"] =  Db::table('foto')->where('id', $frontId)->value('gallery_folder');
    $galleryLink= Db::table('foto')->where('id', $frontId)->value('gallery_folder');
    
    $items = [ ];
    
    $files = File::allFiles( 'storage/app/media/' .$galleryLink. '/' );

     foreach ($files as $item) {
           $items[] = $item->getFilename(); 
             $this["path"] = $item;  //I get everything except correct image name.
      }
     

     sort($items, SORT_NUMERIC); // Bigest file number first
       $this['gallery'] = $items;
       
}

标签: phptwigoctobercms

解决方案


推荐阅读