Getting id from stream in a loop for use in edit form pyrocms -


i using pyrocms streams module loop through content

{{ 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 go here using gallery stream -->  {{ /streams:gallery }} 

i id of current looped item , use in stream form edit content. so

{{ 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 }} 

i want able id value , pass in

edit_id="id-value-here" 

i figured might work

edit_id="{{id}}" 

but lex parser breaking inside of stream inside of stream.

i not sure if possible values stream use in child stream. there way achieve somehow? thanks

edit

regarding issue , using [segments]

this works using url segments id passed. example

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

where [segment_3] , in case, id stream item. awesome. in code initial example not work using streams id or {{ id }}

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

should work.

see pyrocms tags documentation - using tags , variables in tag parameters more information.

generally can omit curly braces if using variable tag parameter, or plugin call without parameters.

// update

here example implementation using custom plugin circumvent problems nested tag calls:

create new plugin in addons/shared_addons/plugin called "customplugin.php"

code:

<?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); } 

create folder "partials" in theme folder, , add "galery_form.html", contains markup stream form:

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

replace form code in galery layout/view plugin call:

{{ customplugin:galeryform galery_id=id }} 

you can of course change name of plugin, make sure classname matches filename + 'plugin_' prefix, , change plugin call accordingly.

it's easier work custom plugins, nesting lex tags.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -