İlave alanları şablonda kullanmak istediğimizde sadece ilave alan boş değilse ve boşsa kontrollerini yapabiliyoruz.
Fakat bu her zaman yeterli olmuyor, daha esnek kontol için bu düzenlemeyi kullanabilirsiniz.
Mevcut yetenekleri :
İlave alan buna eşitse : ( yap )
İlave alan buna eşitse veya bunlardan biriyse : ( yap )
İlave alan buna eşitse : ( yap ) : eşit değilse : (yap )
İlave alan buna eşitse veya bunlardan biriyse : ( yap ) : eşit değilse : (yap )
Programlama dillerinden aşina olduğumuz if - else yapısı ile bu kontolleri yapabilirsiniz.
Örnek olarak "year" adındaki ilave alanı şablonumuzda bu şekilde koşullandırabiliriz.
Kullanabileceğiniz dosyalar : shortstory.tpl, fullstory.tpl, [custom].tpl
XField Adı : year
if( isset($view_template) AND $view_template == "rss" ) {$category_id = $row['category']; // MWS Smart XField Hack
if ( strpos( $tpl->copy_template, "{if xfield=" ) ) {
if ( isset( $xfieldsdata ) ) $xfdata = &$xfieldsdata;
else $xfdata = xfieldsdataload( $row['xfields'] );
if ( preg_match_all( "#\{if xfield=['\"](.+?)['\"] ([not-]*)eq=['\"](.+?)['\"]\}[\s\n\t]*(.+?)[\s\n\t]*\{\/if\}#im", $tpl->copy_template, $matches1 ) ) {
$length = count( $matches1[0] );
for ( $x = 0; $x <= $length; $x++ ) {
if ( in_array( $matches1[1][$x], array_keys( $xfdata ) ) ) {
if ( !empty( $matches1[2][$x] ) && $matches1[2][$x] == "not-" ) {
if ( ! in_array( $xfdata[ $matches1[1][$x] ], explode("|", $matches1[3][$x] ) ) ) { $tpl->copy_template = str_replace( $matches1[0][$x], $matches1[4][$x], $tpl->copy_template ); }
else { $tpl->copy_template = str_replace( $matches1[0][$x], "", $tpl->copy_template ); }
} else {
if ( in_array( $xfdata[ $matches1[1][$x] ], explode("|", $matches1[3][$x] ) ) ) { $tpl->copy_template = str_replace( $matches1[0][$x], $matches1[4][$x], $tpl->copy_template ); }
else { $tpl->copy_template = str_replace( $matches1[0][$x], "", $tpl->copy_template ); }
}
} else {
$tpl->copy_template = str_replace( $matches1[0][$x], "", $tpl->copy_template );
}
}
}
if ( preg_match_all( "#\{if xfield=['\"](.+?)['\"] ([not-]*)eq=['\"](.+?)['\"]\}[\s\n\t]*(.+?)[\s\n\t]*\{else\}[\s\n\t]*(.+?)[\s\n\t]*\{\/if\}#im", $tpl->copy_template, $matches2 ) ) {
$length = count( $matches2[0] );
for ( $x = 0; $x <= $length; $x++ ) {
if ( in_array( $matches2[1][$x], array_keys( $xfdata ) ) ) {
if ( !empty( $matches2[2][$x] ) && $matches2[2][$x] == "not-" ) {
if ( ! in_array( $xfdata[ $matches2[1][$x] ], explode("|", $matches2[3][$x] ) ) ) { $tpl->copy_template = str_replace( $matches2[0][$x], $matches2[4][$x], $tpl->copy_template ); }
else { $tpl->copy_template = str_replace( $matches2[0][$x], $matches2[5][$x], $tpl->copy_template ); }
} else {
if ( in_array( $xfdata[ $matches2[1][$x] ], explode("|", $matches2[3][$x] ) ) ) { $tpl->copy_template = str_replace( $matches2[0][$x], $matches2[4][$x], $tpl->copy_template ); }
else { $tpl->copy_template = str_replace( $matches2[0][$x], $matches2[5][$x], $tpl->copy_template ); }
}
} else {
$tpl->copy_template = str_replace( $matches2[0][$x], "", $tpl->copy_template );
}
}
}
unset( $xfdata, $matches1, $matches2 );
}
// MWS Smart XField Hack