<![CDATA[ Execute snippet only for specific language - My Forums]]> https://forums.modx.com/thread/?thread=45464 <![CDATA[Re: Execute snippet only for specific language]]> https://forums.modx.com/thread/45464/execute-snippet-only-for-specific-language#dis-post-263095
To be more specific:

This is the call:
[!ConditionalRedirect? &mode=`yams` &tv=`available` &lang=`(yams_id)` &cond=`0`!]


This is the real snippet:

<?php
$docid = (isset($docid))? $docid: $modx->documentIdentifier;
$mode = (isset($mode))? $mode :"";
$tv = (isset($tv))? $tv :"";
$lang = (isset($lang))? $lang :"";
$cond = (isset($cond))? $cond :"";
$parent = $modx->getParent($docid,1,'id');
$tv = $tv.'_'.$lang;
$tvval='';

if ($tv!="_") {
  $tvarray = $modx -> getTemplateVarOutput( $tv, $docid, $published = 1 );
  $tvval = $tvarray[$tv];
}

if ($parent['id'] != false) {
    $redirectId= $parent['id'];
    $redirectUrl= $modx->makeUrl($redirectId);
} else {
    $redirectUrl= $modx->makeUrl($modx->config['site_start']);
}
if ($tvval==$cond){
	if ($mode=="yams"){
	    header( 'Location: ' . substr($redirectUrl,1) , TRUE, 303);
	    return;
	}
	else {
	  return $modx->sendRedirect($firstChildUrl);
	}
}
else {
	//Debug
	return 'Parent: '.$parent['id'].' Redirect: '. $redirectUrl;
}
?>


I tried with setting the page to non cacheable and putting the snippet in the template and in the specific language content.
Always the same behavior. Or may be I’m missing something?]]>
ddim Nov 25, 2009, 06:11 AM https://forums.modx.com/thread/45464/execute-snippet-only-for-specific-language#dis-post-263095
<![CDATA[Re: Execute snippet only for specific language]]> https://forums.modx.com/thread/45464/execute-snippet-only-for-specific-language#dis-post-263094 PaulSuckling Nov 25, 2009, 03:58 AM https://forums.modx.com/thread/45464/execute-snippet-only-for-specific-language#dis-post-263094 <![CDATA[Execute snippet only for specific language]]> https://forums.modx.com/thread/45464/execute-snippet-only-for-specific-language#dis-post-263093 I need to execute a snippet only for specific page language and cannot figure out how to do it
Or may be this is not possible.

There is a snippet like this:

[[ConditionalRedirect? &variable=`<tvar>` &condition=`<value>`]]

the snippet functionality is something like:

if (ValueOfTV == ValueOfCondition) {header( ’Location: ’ . $url , TRUE, 303);

So far so good. This construct is in general working.

But if I use it like this:

- I have multilingual variable ( var_bg and var_en)
- var_bg=1 var_en=0
- I call the snippet like this [[ConditionalRedirect? &variable=`var_(yams_id)` &condition=`0`]]
- The snippet can be in a template, or in in the content (for each language)

The expectation is to have the redirect if the page language is "en"
The reality is that the redirect happens always.

I’m not an expert in yams or in modx, so I don’t know the internals of parsing and executing the snippets,
but from the behavior my conclusion is that the page is rendered (processed) in all available languages independent of the current.

Is it possible to avoid this behavior and to execute the snippet only for current language?



]]>
ddim Nov 25, 2009, 03:30 AM https://forums.modx.com/thread/45464/execute-snippet-only-for-specific-language#dis-post-263093