Custom Placeholders

The Challange

I have a site in four languages, with a single news item "teaser" on the home page. I have a Ditto call on each home page with that section's language and the ID of the parent to its news folder. I want to use the same view template chunk for all four languages, but the "read more…" link text to the actual news article needs to be taken from Ditto's language files.

The Solution

This is in two parts. The first part, of course, is to add the variable to each language file:

$_lang['open_dbg_console'] = "Open Debug Console";
$_lang['save_dbg_console'] = "Save Debug Console";
// Custom Text
$_lang['details'] = "Read More";

Now, I need to be able to have a placeholder to add that gets this value from the language file specified in the Ditto call's parameters. This means creating a custom extender.

Extenders are found in the assets/snippets/ditto/extenders/ folder. So after some help from the forums and on the Evo irc channel, I made this file:

$placeholders['details'] = array("*","displayDetail");
    function displayDetail($resource){//Not sure if the $resource is needed
    return $GLOBALS['ditto_lang']['details'];

The key to this is the $GLOBAL['ditto_lang']['details'] array value. This lets you access any of the elements of the $_lang array in the language files.

So what this does is add a placeholder, 'details', to the Ditto array of placeholders to set, and fills that value with the specified "dispayDetail" function. In this case, my function was very simple, it just returns the desired language file array element.

Finally, add the custom extender to the ditto call:


More details on the specifics of extenders can be found in the Ditto extenders documentation.

Suggest an edit to this page.