Do you have some feature in mind that you'd love to see in Couch? Let us know.
3 posts Page 1 of 1
Sometimes I would like to build a command, e.g. <cms:db_persist ...> dynamically and execute it later using <cms:embed code=variable_with_command />

Unfortunately this is not possible at the moment, at least not without cheating. Trendoman once posted a tip how to do it, I think I remember doing it with omitting the first < before cms:... tag.

Using an additional parameter in the <cms:capture ... exec='0'> and <cms:set ... exec='0'> commands would solve this in a proper way.

Regards,
Olliwalli
@olliwalli, I edited the topic's Subject, hope you don't mind.

CouchCMS supports dynamic params as _fields='' for <cms:db_persist> tag. Supply _fields with a regular array and execute db_persist whenever necessary. It seems to me (from the reference you mentioned about my other post) the origin of your request has something to do with dynamically built variable names.
"Capture" only the required fields (as json) and pass them onto db_persist tag when necessary, just like you'd 'exec' saved db_persist.

If above is not helping, it is never late to try a function. As you are perfectly aware, functions are registered but do not execute code inside them before the moment you're calling them. Here is an example and please don't forget to change _masterpage and field_name -

Code: Select all
<cms:func 'persist_on_demand' field_name='' field_value=''>

   <cms:set my_fields = '[]' is_json='1' />
   <cms:put var="my_fields.<cms:show field_name />" value=field_value />
   <h2>Saving: <cms:show my_fields as_json='1' /></h2>

   <cms:db_persist _mode='create' _auto_title='1' _masterpage='test.php' _fields = my_fields>
        <cms:if k_success>
            <h2>Saved: <cms:show k_last_insert_page_name /></h2>
        <cms:else_if k_error />
            <h2>Error:<cms:show k_error /></h2>
        </cms:if>
    </cms:db_persist>

</cms:func>

<cms:call 'persist_on_demand' field_name='desc' field_value='Hello, there!' />


Please let us know if that does not help either.

My Documentation, Addons, Functions.
Join COUCH:TALK telegram channel

Thanks Trendoman!

This is an interesting hint - I didn't know this parameter. This opens the possibility to convert the post params to a json, manipulate it if necessary and then save it to database. Great!

I'm sure this will help me to make the code smaller and more elegant.

Regards,
Oliver
3 posts Page 1 of 1