<![CDATA[ Modx Chunk Ifs - My Forums]]> https://forums.modx.com/thread/?thread=103956 <![CDATA[Modx Chunk Ifs]]> https://forums.modx.com/thread/103956/modx-chunk-ifs#dis-post-559088 [[*id:eq=`resource id`:or:eq=`resource 2 id`:then=``:else=``]]]]> zzfkelvin Jun 15, 2018, 06:34 AM https://forums.modx.com/thread/103956/modx-chunk-ifs#dis-post-559088 <![CDATA[Re: Modx Chunk Ifs]]> https://forums.modx.com/thread/103956/modx-chunk-ifs#dis-post-559146
Put the scripts in three chunks named Chunk28, Chunk23-24-39, and DefaultChunk. Then do this.

Put this where you want the script:

[[!AddScript]]


Create a snippet called AddScript with this code:

/* AddScript snippet */
$chunkName = '';

$template = $modx->resource->get('template');

switch($template) {
   case 28: 
     $chunkName = 'Chunk28';
     break;

   case 23:
   case 24:
   case 37:
     $chunkName = 'Chunk23-24-37';
     break;
   
   default:
     $chunkName = 'DefaultChunk';
     break;
}

return $modx->getChunk($chunkName);


It will be much faster and infinitely easier to maintain.]]>
BobRay Jun 20, 2018, 03:37 AM https://forums.modx.com/thread/103956/modx-chunk-ifs#dis-post-559146
<![CDATA[Re: Modx Chunk Ifs]]> https://forums.modx.com/thread/103956/modx-chunk-ifs#dis-post-559136 Quote from: iusemodx at Jun 15, 2018, 09:51 PM
@zzfkelvin

Are you using Revo ?

yes]]>
zzfkelvin Jun 19, 2018, 03:34 AM https://forums.modx.com/thread/103956/modx-chunk-ifs#dis-post-559136
<![CDATA[Re: Modx Chunk Ifs]]> https://forums.modx.com/thread/103956/modx-chunk-ifs#dis-post-559135 Quote from: BobRay at Jun 17, 2018, 05:44 AM
Stuff like this is infinitely faster and more reliable in PHP, and not very complicated:
(I'm guessing at what you want -- feel free to clarify)

[[!SomeSnippet]]



/* SomeSnippet code */

$output = ''
$docId = $modx->resource->get('id');

if ($docId == 12 || $docId == 22) {
   $output = 'something';
} else {
   $output = 'something else';
}

return $output;


I'm trying to add some schema codes into our website, I created a chunk named XJTLU_Schema, and call this chunk inside site.head chunk.
In this XJTLU_schema chunk, I set some condition to add schema codes according to different page template, for example,

[[*template:eq=`28`:then=`
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Person",
"name": "[[+sedona.name]]",
"honorificSuffix": "[[+sedona.highdegree]]",
"jobTitle": "[[+sedona.rank]]",
"description": "[[+sedona.bio]]",
"image": "[[+sedona.image]]",
"address": "[[+sedona.office]]",
"email": "[[+sedona.email]]",
"telephone": "[[+sedona.phone]]"
}
</script><!--Schema for staff-->
`:else=``]]

[[*template:eq=`23`:or:is=`24`:or:is=`37`:then=`
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "EducationalOrganization",
"name": "[[*longtitle]]",
"description": "[[*content]]",
"address": "[[*contactAddress:nl2br]]",
"email": "[[*contactEmail]]",
"telephone": "[[*contactPhone]]"
}
</script><!--Schema for department,centre & research insitution-->
`:else=``]]

I only need to identify some key templates with different types, such as person, organization, event.....But for the other pages, I don't want to type the template ID one by one, I think if it could has some code like "else" to apply one all the other pages.]]>
zzfkelvin Jun 19, 2018, 02:16 AM https://forums.modx.com/thread/103956/modx-chunk-ifs#dis-post-559135
<![CDATA[Re: Modx Chunk Ifs]]> https://forums.modx.com/thread/103956/modx-chunk-ifs#dis-post-559114 (I'm guessing at what you want -- feel free to clarify)

[[!SomeSnippet]]



/* SomeSnippet code */

$output = ''
$docId = $modx->resource->get('id');

if ($docId == 12 || $docId == 22) {
   $output = 'something';
} else {
   $output = 'something else';
}

return $output;

]]>
BobRay Jun 17, 2018, 05:44 AM https://forums.modx.com/thread/103956/modx-chunk-ifs#dis-post-559114
<![CDATA[Re: Modx Chunk Ifs]]> https://forums.modx.com/thread/103956/modx-chunk-ifs#dis-post-559109
Are you using Revo ?]]>
iusemodx Jun 15, 2018, 09:51 PM https://forums.modx.com/thread/103956/modx-chunk-ifs#dis-post-559109
<![CDATA[Re: Modx Chunk Ifs]]> https://forums.modx.com/thread/103956/modx-chunk-ifs#dis-post-559090 Quote from: lkfranklin at Jun 15, 2018, 06:44 AM
Yeah but in chunks the placeholder would be a [[+id]] instead of [[*id]]

how should I write the else if code?

[[*id:eq=`resource id`:or:eq=`resource 2 id`:then=`

`:elseif:*id:eq=`b`:then=`

`]]

is it?]]>
zzfkelvin Jun 15, 2018, 06:55 AM https://forums.modx.com/thread/103956/modx-chunk-ifs#dis-post-559090
<![CDATA[Re: Modx Chunk Ifs]]> https://forums.modx.com/thread/103956/modx-chunk-ifs#dis-post-559089 lkfranklin Jun 15, 2018, 06:44 AM https://forums.modx.com/thread/103956/modx-chunk-ifs#dis-post-559089