从循环中获取id以在编辑形式pyrocms中使用

时间:2015-06-10 13:26:08

标签: pyrocms pyrocms-lex

我正在使用pyrocmsstreams module来循环播放内容

{{ streams:gallery}}

<div class="col-lg-3 col-md-4 col-sm-4">
    <a href="#">
        <div class="ratio" style="background:url({{gallery_images:image}})"></div>
    </a>
    <div class="text-center">
        <h5>{{title}}</h5>
    </div>
</div>

<!-- FORM CODE BELOW WILL GO HERE USING THE GALLERY STREAM -->

{{ /streams:gallery }}

我想获取当前循环项的id,然后以流形式使用它来编辑内容。像这样

{{ if user:logged_in }}
{{ streams:form stream="gallery" mode="edit" edit_id="1" include="page_image|deschtml"}}
{{ form_open }}

<span class="click-to-edit">
    <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit
</span>
<span class="inline-edit">

    {{ error }}
    {{ page_image:input }}
    {{ deschtml:input }}
    {{ form_submit }}

    <button class="inline-close pull-right" type="button">Cancel</button>
</span>
{{ form_close }}
{{ /streams:form }}
{{ endif }}

我希望能够获取id值并将其传递给

edit_id="ID-VALUE-HERE"

我认为这样的事情可能会起作用

edit_id="{{id}}"

但是lex解析器正在流内部的流中破坏。

我不确定是否可以从流中获取要在子流中使用的值。有办法以某种方式实现这一目标吗?感谢

修改

关于此问题并使用[segments]

这完全使用url段作为传递的id。例如

{{ streams:form stream="custom_details" mode="edit" edit_id="[segment_3]" include="page_image|deschtml"}}

其中[segment_3],在我的例子中,这是流项的id。哪个很棒。但是,与初始示例的代码一样,使用流id{{ id }}

无效

1 个答案:

答案 0 :(得分:0)

{{ streams:form stream="custom_details" mode="edit" edit_id=id include="page_image|deschtml" }}

应该有用。

有关详细信息,请参阅PyroCMS Tags documentation - Using Tags and Variables in Tag Parameters

一般情况下,如果使用变量作为标记参数或不带任何参数的插件调用,则可以省略花括号。

//更新

以下是使用自定义插件来规避嵌套标记调用问题的示例实现:

在addons / shared_addons / plugin中创建一个名为“customplugin.php”的新插件

代码:

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Plugin_Customplugin extends Plugin {

    public function galeryform()
    {
        $id = $this->attribute('galeryid', false);

        if( ! $id ) {
            return;
        }

        return $this->theme_view('partials/galery_form', array('galeryid' => $id), true);
}

在主题文件夹中创建一个“partials”文件夹,然后添加“galery_form.html”,其中包含您的信息流表单的标记:

{{ streams:form stream="custom_details" mode="edit" edit_id=galeryid include="page_image|deschtml"}}
[ ... and the rest of your markup ... ]

使用插件调用替换galery布局/视图中的表单代码:

{{ customplugin:galeryform galery_id=id }}

您当然可以更改插件的名称,只需确保类名与文件名+'Plugin_'前缀匹配,然后相应地更改插件调用。

使用自定义插件几乎总是比嵌套lex标签更容易。

相关问题