if ( !isset($my_chunk) ) {
$my_chunk = 'name_of_my_chunk'; // Default Chunk
}
$output.=$modx->parseChunk( $my_chunk, $row, '[+', '+]');
if ( !isset($my_chunk) ) {
$my_chunk = '<table>[+content+]</table>'; // Default Chunk
}
$output.=$modx->parseChunk( $my_chunk, $row, '[+', '+]');$myTpl = isset($my_chunk)? $my_chunk: '<table>[+content+]</table>'; $output.=$modx->parseChunk( $myTpl, $row, '[+', '+]');
Becoming even more common in Revo where you can pass content through parameters with no problems, unlike the current parser which does not allow complex HTML due to the limitation against ? & and =.
That’s a common thing to do if the content is fairly short.
$myTpl = isset($item_chunk)? $item_chunk: 'Page Title: [+pagetitle+]<br/>'; $output.=$modx->parseChunk( $myTpl, $row, '[+', '+]');
Hmm... now that I’m sitting down to put in some default values, I can’t seem to make this work.
Here’s what I have in a nutshell:
$myTpl = isset($item_chunk)? $item_chunk: 'Page Title: [+pagetitle+]<br/>'; $output.=$modx->parseChunk( $myTpl, $row, '[+', '+]');
I can’t shake the feeling that the "parseChunk" function does something tricky because it’s expecting to look up a chunk by its name and THEN get the string with the placeholders... giving it the string right off the bat just doesn’t feel right to me...
$myTpl = isset($item_chunk)? $item_chunk: 'name_of_default_chunk'; $output.=$modx->parseChunk( $myTpl, $row, '[+', '+]'); return $output;
Thanks for the note, Bob. What I’m trying to do is create a Snippet that’s more portable. To achieve that, I’d like to have the default chunk contents contained within the Snippet. In my example, you can pass the name of the chunk to use for the "item_chunk", but if no name is supplied (and lets assume that the chunk doesn’t even exist), I’d like to just have the default text that would have come from the chunk if it did exist and its name had been passed. E.g. something simple like "Page Title: [+pagetitle+]". I’d like to have within the Snippet the text from that chunk so if someone hadn’t created a specialized chunk for this snippet, they could just use the default values that the Snippet had on board. Does that make sense?
$placeholders = array(
'[+pagetitle+]' => 'Page Title:',
'[+something else+]' => 'Other'
}
str_replace( array_keys( $placeholders ), array_values( $placeholders ), $tpl );