I'm always wondering why people so eagerly avoid to have more than one template. Concerning performance, isn't it much better than using so many modifiers?I agree; many Templates with reusable or inherited sections via Chunks and/or Template Variables is a much better approach and can help avoid logic appearing in tags, which degrades performance.
[[!include? &file=`assets/templates/inc/newslisting.php]]
<?php $id='[[*id]]'; if ($id = "3" || $id = "24" || $id = "35" || $id = "38" || $id = "42" || $id = "44" || $id = "47" || $id = "32"){ echo "[[!include? &file=`assets/templates/inc/newslisting.php]]"; } elseif ($id = "54" || $id = "64" || $id = "75"){ echo "[[!include?&file=`assets/templates/inc/bloglisting.php]]"; } elseif ($id = "56"){ echo "[[!include?&file=`assets/templates/inc/contact.php]]"; } else { echo "[[!include?&file=`assets/templates/inc/textContent.php]]"; };
<?php $output = ''; if ($id == "3" || $id == "24" || $id == "35" || $id == "38" || $id == "42" || $id == "44" || $id == "47" || $id == "32"){ output = '[[!include? &file=`assets/templates/inc/newslisting.php]]'; } elseif ($id == "54" || $id == "64" || $id == "75"){ output = '[[!include?&file=`assets/templates/inc/bloglisting.php]]'; } elseif ($id == "56"){ output = '[[!include?&file=`assets/templates/inc/contact.php]]'; } else{ output = '[[!include?&file=`assets/templates/inc/textContent.php]]'; } return $output;
[[!templateSwitcher? &id=`[[*id]]`]]
[[!include? &file=`assets/templates/inc/newslisting.php]]
[[!include? &file=`assets/templates/inc/newslisting.php`]]
<?php //[[!templateSwitcher? &newslisting=`3,24,35,38,42,44,47,32` &bloglisting=`54,64,75` &contact=`56` &default=`textContent`]] $id = $modx->resource->get('id'); unset($scriptProperties['default']); foreach ($scriptProperties as $file => $ids) { $ids = explode(',', $ids); if (in_array($id, $ids)) { $params['file'] = 'assets/templates/inc/' . $file . '.php'; return $modx->runSnippet('include', $params); } } $params['file'] = 'assets/templates/inc/' . $default . '.php'; return $modx->runSnippet('include', $params);
[[!templateSwitcher? &newslisting=`3,24,35,38,42,44,47,32` &bloglisting=`54,64,75` &contact=`56` &default=`textContent`]]
[[!getContext:is=`web`:then=`doSomething`:elseif=`getContext`:is=`contextTwo`:then=`doSomethingElse`]]
Bump!
I know this thread is ancient but it's basically asking what I want to know...I was just wondering if anything has changed in 2 years?
Ideally I would like to do something like
[[!getContext:is=`web`:then=`doSomething`:elseif=`getContext`:is=`contextTwo`:then=`doSomethingElse`]]
obviously this call doesnt make sense to modx but hopfeully you get the idea of what I am trying to accomplish...I have a modx install with 4 different contexts and sometimes only need small changes to each one. I dont want to use different templates as the differences are generally quite small and I dont want to have to change the same thing in 4 places every time i need to make a change...
Many thanks!
Matt
[[getResourceField? &id=`[[BabelTranslation? &resourceId=`13`&contextKey=`[[*context_key]]`]]` &field=`DefaultPhoneNumber` &processTV=`1` &default=`Sorry, no data available`]]
What exactly are you after, whats your usecase, exactly? There are several solutions posted in this thread.