by
KK » Sun Dec 14, 2014 3:07 am
We can use only a single template for editing all cloned pages.
This we can do by supplying it the id of the page to edit as querystring parameter (i.e. though its URL).
So, for example, in your case if we use a single non-clonable template named 'edit_fruit.php' for editing fruits, the template can be invoked as -
http://yoursite.com/edit_fruit.php?id=23
or
http://yoursite.com/edit_fruit.php?id=42
where we use a querystring parameter named 'id' to supply the page id to edit.
We can craft this URL automatically. Since you are using 'fruit_list.php' to list all fruits, you'd have a cms:pages loop in it. We can place the following code to add an EDIT link to all pages being listed -
- Code: Select all
<cms:pages masterpage='fruit.php' >
...
...
<a href="<cms:link 'edit_fruit.php' />?id=<cms:show k_page_id />">EDIT</a> <br/>
</cms:pages>
So now we can invoke the 'edit_fruit.php' template with the page id to edit.
Here is how we retrieve that ID in 'edit_fruit.php' and then use it within the DBF -
If you are using Couch v1.4.5, use the following code -
- Code: Select all
<!-- get the 'id' parameter from querystring -->
<cms:set my_page_id="<cms:gpc method='get' var='id' />"/>
<!-- make sure it is a valid value before using it -->
<cms:if "<cms:validate my_page_id validator='non_zero_integer' />">
<cms:form
masterpage='fruit.php'
mode='edit'
page_id=my_page_id
enctype="multipart/form-data"
method='post'
anchor='0'
>
...
...
</cms:form>
</cms:if>
If, however, you are using an older version of Couch, we'll have to use a bit of PHP to validate the id being passed. Here is the equivalent of the code above -
- Code: Select all
<!-- get the 'id' parameter from querystring -->
<cms:set my_page_id="<cms:gpc method='get' var='id' />"/>
<!-- make sure it is a valid value before using it -->
<cms:php>
global $FUNCS, $CTX;
if( !$FUNCS->is_non_zero_natural($CTX->get('my_page_id')) ){
$CTX->set( 'my_page_id', '' );
}
</cms:php>
<cms:if my_page_id >
<cms:form
masterpage='fruit.php'
mode='edit'
page_id=my_page_id
enctype="multipart/form-data"
method='post'
anchor='0'
>
...
...
</cms:form>
</cms:if>
Hope this helps.