Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
hello all, am I attempting the impossible or just doing it wrong?

I want to show a cloaked email address (a global field) within an editable region:

Code: Select all
<cms:show "<cms:cloak_email "<cms:get_custom_field 'email_address' masterpage='globals.php' />" />" />


The above tags are within <cms:editable> ... </cms:editable>

The end result is that the message
(Please enable JavaScript to view this email address)
is shown followed by the encrypted email address.

:?:
Hi,

We'll have to use shortcodes (http://www.couchcms.com/docs/miscellane ... codes.html) to achieve that.

The kfunctions.php given the documentation already has a shortcode for obfuscating emails. We'll make a little modification to it to make it work the way you want.
Please find the following lines and replace the highlighted line..
// 6.
// Obfuscate email
// Usage: [mailto]email@mydomain.com[/mailto]
$FUNCS->register_shortcode( 'mailto', 'mailto_handler' );
function mailto_handler( $params, $content=null ){
global $FUNCS;

// Create Couch script.. we'll use the 'cloak_email' tag to encrypt email
$html = "<cms:cloak_email email='{$content}' />";

// Pass on the code to Couch for execution using the 'embed' function
return $FUNCS->embed( $html, $is_code=1 );
}

.. as follows
// 6.
// Obfuscate email
// Usage: [mailto]email@mydomain.com[/mailto]
$FUNCS->register_shortcode( 'mailto', 'mailto_handler' );
function mailto_handler( $params, $content=null ){
global $FUNCS;

// Create Couch script.. we'll use the 'cloak_email' tag to encrypt email
$html = "<cms:cloak_email \"<cms:get_custom_field 'email_address' masterpage='globals.php' />\" />";

// Pass on the code to Couch for execution using the 'embed' function
return $FUNCS->embed( $html, $is_code=1 );
}

Now (as explained in the docs), if your editable region was, for example, named 'my_content' and this is how you were outputting its content in the template
Code: Select all
<cms:show my_content />

simply enclose it with <cms:do_shortcodes> tags like this
Code: Select all
<cms:do_shortcodes><cms:show my_content /></cms:do_shortcodes>

This will now make Couch execute any shortcodes the user inputs into the editable region.

You can now output the obfuscated email simply by inputting the following shortcode within the editable region
Code: Select all
[mailto]

Hope this helps.
Apologies - I seem to have a mental block over realising that the answer is "shortcode". And it isn't so very hard at all - all done and working. Thanks!
3 posts Page 1 of 1