Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
15 posts Page 2 of 2
Thank you!

I am trying to master shortcodes and am a bit confused. I get the php part and even the basic logic.

Content of my kfunctions.php file which is in the CouchCMS root:


$FUNCS->register_shortcode( 'hello', 'hello_handler' );

function hello_handler( $params, $content=null ){
return '<h1>Hello from a shortcode!</h1>';

I'm new to php but doesn't there need to be a close tag? ?>

What I don't get is where to put these tags.

I have a template (basic HTML file structure) that has an editable region:



Custom HTML here


I tried wrapping the editable tags with <cms:do_shortcodes>...</cms:do_shortcodes> and then writing the [hello] inside the editable area to test it. It doesn't render on the page.

Do I need to place the code within the template tags at the top?:

<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Contact Us' order='10'>


<cms:show main_content />



I tried this but it isn't working either.

I'm not a PHP guru and would appreciate it if I didn't receive any flames for what might be a stupid question. I'm missing something major even though I thoroughly read the shortcodes documentation page. Please don't just point me there.

Any help would be appreciated.

@TFG, I've posted an explanation in your other thread on the same topic - viewtopic.php?p=23300#p23300

Hope it helps.
Hi TFG. @KK gave a thorough answer to your question, but didn't touch on the bit about the php close tag. It's a pretty trivial question, but was surprising to me, too. You don't need the closing php tag. I guess when the code comes to the end, it stops executing. Period.

PHP is usually mixed with html, and the closing tag would be necessary to separate it from html in a document.
Code: Select all
         <?php echo 'Hi there, world.'; ?>

But just to come to a stop, or as in this case to go on to more php code, you don't need it. As far as I know, none of the Couch files have closing php tags just to end the file. Maybe such a reckless disregard for the closing tag is just one of @KK's stylistic flourishes. Nonetheless, it works.
@tim, not using the closing PHP tag is, in fact, a recommended practice.

The reason being that it is very easy to inadvertently leave a white-space after the closing tag, if you choose to use one.

This, of course, will only provide yet another avenue for the dreaded 'Cannot modify header information - headers already sent" error we encounter only too often (viewtopic.php?f=4&t=53).
15 posts Page 2 of 2

Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 2 guests