Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
26 posts Page 3 of 3
To use <cms:call> with a func, we first need to embed that func code somewhere.

That is no longer necessary with the new addon —

UPDATE: Addon Tweakus Dilectus » "Func-on-demand" has been published, intended to autoload funcs placed in snippets.

What a coincidence, it's 4th of July, congratulations to those who celebrate :)

4thJuly.png
4thJuly.png (14.64 KiB) Viewed 21577 times
UPDATE: A proper dedicated documentation page at Midware Concepts » Reusable Functions has been published.
A showcase of working with objects PHP-style.

Code: Select all
<!-- create empty object -->
<cms:set obj = '[]' is_json='1' />

<!-- set property -->
<cms:set obj.created = '0' />


<!-- Add magic method to object that changes a property -->
<cms:func _into='obj.__set' property='' value='' _scope='parent'>
    <cms:put var="<cms:concat 'obj.' property />" value=value scope='parent' />
</cms:func>


<!-- show property has initial value -->
<cms:show obj.created /> == 0<br>


<!-- invoke method -->
<cms:call_ex obj.__set 'created' '1' />


<!-- show value is changed -->
<cms:show obj.created /> == 1<br>


Magic method :lol:
Magic method indeed, @trendoman :)
Hi Trendoman,
I needed to search by page title. All my searches on the forum lead me here :) But I couldn't run the code you made with the call method. i am getting this error : "Error: <cms:func />: "search_by_title" not available"

I don't know much about php. how can i run this code?

Regards
Depends on the use case.
Use Couch Search. See https://docs.couchcms.com/concepts/using-search.html It searches within titles and other regions, placing page higher in search results if the word is found in title.

Hi Trendoman,
I needed to search by page title. All my searches on the forum lead me here :) But I couldn't run the code you made with the call method. i am getting this error : "Error: <cms:func />: "search_by_title" not available"

I don't know much about php. how can i run this code?

Regards
26 posts Page 3 of 3