遍历pyrocms模板变量中的数组

发布于 2024-12-05 08:59:06 字数 1164 浏览 1 评论 0原文

我已经调整了文件插件来列出所有文件夹,并在其中列出所有文件。

代码或多或少像这样:

$folders = assoc_array_prop($this->file_folders_m->get_all());
$counter = 1;
foreach ($folders as $key => $folder) {
$folder->index = str_pad($counter++, 2, '0', STR_PAD_LEFT);
$this->file_m->where('folder_id', $folder->id);
$files = $this->file_m->get_all();
$folder->files = assoc_array_prop($files);
}
return $folders;

现在,问题是,如何访问模板中每个文件夹的每个 $folder->files ?这似乎不起作用:

{pyro:mymod:file_listing}
    <div class="files_column">
    <h2><span class="files-index">&#123;index}</span> &#123;name}</h2>
{pyro:files}


<div class="file-item">

<span class="file-type">{id}</span>

<div class="file-data">
<span>{filename}</span>
<br/>
<span class="file-links">
<a href="#">View</a>
<a href="#">Download</a>
</span>

</div>
</div>
{/pyro:files}


</div>
{/pyro:mymod:file_listing}

为了澄清这一点......根据我看到数据出现的次数,{files}循环似乎工作正常。问题是我似乎无法访问它的属性,例如 {filename}。

谢谢, 伊格纳西奥

I've adapted the File plugin to list all folders and inside of them list all files.

The code is more or les like this:

$folders = assoc_array_prop($this->file_folders_m->get_all());
$counter = 1;
foreach ($folders as $key => $folder) {
$folder->index = str_pad($counter++, 2, '0', STR_PAD_LEFT);
$this->file_m->where('folder_id', $folder->id);
$files = $this->file_m->get_all();
$folder->files = assoc_array_prop($files);
}
return $folders;

Now, the thing is, how can I access each $folder->files for each folder in the template? This doesn't seem to work:

{pyro:mymod:file_listing}
    <div class="files_column">
    <h2><span class="files-index">{index}</span> {name}</h2>
{pyro:files}


<div class="file-item">

<span class="file-type">{id}</span>

<div class="file-data">
<span>{filename}</span>
<br/>
<span class="file-links">
<a href="#">View</a>
<a href="#">Download</a>
</span>

</div>
</div>
{/pyro:files}


</div>
{/pyro:mymod:file_listing}

To clarify on this... the {files} loop seems to work ok, based on the number of times I see the data appear. The problem is that I can't seem to acces its attributes, like {filename}.

Thanks,
Ignacio

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自此以后,行同陌路 2024-12-12 08:59:06

我认为你做错的第一件事是使用内部的pyro标签{pyro:files},我很确定它只会调用核心pyro:files插件。

我所做的一种遍历形式在标签中似乎不可能实现,那就是使用外部标签的属性来查找内部标签的信息:

像这样:

{pyro:movies:now_showing}

<img src="{img_path}"/>
<p>{pyro:movies:synopsis_snippet id="{movie_id}" length="100"}</p>

{/pyro:movies:now_showing}

所以我使用当前元素中的 movie_id 来获取另一块来自我的插件的数据。我的插件有一个 now_showing 和一个 synopsis_snippet 函数。

您可以做的是使用一种列出文件夹的方法和一种列出文件夹的文件的方法,如下所示:

{pyro:my_plugin:folders}

{pyro:my_plugin:list_files_of_folder id="{attribute to lookup folder}"}
{/pyro:my_plugin:list_files_of_folder}

{/pyro:my_plugin:folders}

希望这会有所帮助。 :)

first thing I think you're doing wrong is having the inner pyro tag {pyro:files} which I'm pretty sure will just call the core pyro:files plugin.

What I did to do a form of traversing that didn't otherwise seem possible with tags was to use attributes of the outer tag to find information for the inner tag:

like this:

{pyro:movies:now_showing}

<img src="{img_path}"/>
<p>{pyro:movies:synopsis_snippet id="{movie_id}" length="100"}</p>

{/pyro:movies:now_showing}

so I used the movie_id from the current element to get another piece of data from my plugin. My plugin has a now_showing and a synopsis_snippet function.

What you could do is have a method that lists folders and one that lists files of a folder something like this:

{pyro:my_plugin:folders}

{pyro:my_plugin:list_files_of_folder id="{attribute to lookup folder}"}
{/pyro:my_plugin:list_files_of_folder}

{/pyro:my_plugin:folders}

Hope this helps. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文