Quote from: culd at Sep 07, 2015, 01:21 PMCan you post the code of your snippets and chunks?
I'm digging through the trail of chunks and snippets to post, this is my fist MODX site and it was a learning process. So, in my templates, I am calling a generic top part of the code in a chunk, and in that chunk I am calling uncached my topNavigation snippet:
topNavigation snippet
<?php
// Set URL for anchor page navigation
if ($_SERVER['SERVER_NAME'] == 'dev.mysite.net') {
$fwdAnchorLink = "http://dev.mysite.net";
} else {
$fwdAnchorLink = "http://www.mysite.com";
}
switch ($_COOKIE['market']) {
case "city1":
$fields = array('market_link' => 'city1',
'fwdAnchorLink' => $fwdAnchorLink);
$output .= $modx->getChunk('top_nav', $fields);
break;
case "city2":
$fields = array('market_link' => 'city2',
'fwdAnchorLink' => $fwdAnchorLink,
'someCityShow' => '<li><a href="http://www.mysite.com/extralink/" target="_blank">Extra Link</a></li>'););
$output .= $modx->getChunk('top_nav', $fields);
break;
etc....
}
return $output;
top_nav chunk
<div class="top-nav-container">
<div class="inner">
<nav class="top-nav">
<ul>
[[!showChatLink? &ids=`18,19,22,23,24,25,26,27,28,29,30,31` &extendedChunk=`chatLinkChunk` &basicChunk=`noChatLinkChunk`]]
<li class="contact">800-123-4567</li>
<li><a href="link" target="_blank">Link 1</a></li>
<li><a href="link" target="_blank">Link 2</a></li>
<li><a href="link" target="_blank">Link 3</a></li>
[[+someCityShow]]
</ul>
</nav>
<div class="off-link" align="center">
<a href="http://www.mysite-business.com/" style="padding: 10px 22px; height: 52px; line-height: 1em !important; font-size: 1rem;" target="_blank">For Business<br /><span style="font-weight: normal; font-size: .8em; text-align: center;">800-321-7654</span></a>
</div>
</div>
</div>
I think I may have used fwdAnchorLink in another snippet, and it is just a ghost here, but it is necessary to have someplace in my code in order for anchor links to work on my pages.
The show chat link snippet is just to display the script for chat on certain pages, and is pretty basic:
showChatLink
<?php
$ids = explode(',',$modx->getOption('ids',$scriptProperties,''));
$docid = $modx->resource->get('id');
if (in_array($docid,$ids)) {
$chunk = $extendedChunk;
} else {
$chunk = $basicChunk;
}
return $modx->getChunk($chunk);
So, I can't find anything in the code that would cause a "1" to show up instead of my code, it's pretty basic. The only thing I can maybe think of is that it is being called uncached, but, if it isn't then my extra link for some cities won't show up until the next load of the page. I know it isn't the chat code because I am even running into issues on pages that it isn't being used. It might also be my geo location initial landing and for some reason clearing server cache is causing a cookie mix-up and showing the "1", but I don't understand why.
Just to show, here is my geo location snippet which is Resource 1, so there is no official landing page, just a redirect to the different markets:
geoIP
<?php
include("/path-to-site/assets/geo/geoipcity.inc");
include("/path-to-site/assets/geo/geoipregionvars.php");
$ip_address = $_SERVER['REMOTE_ADDR'];
$gi = geoip_open("/path-to-site/assets/geo/GeoLiteCity.dat", GEOIP_STANDARD);
$record = geoip_record_by_addr($gi, $ip_address);
$request_uri = $_SERVER['REQUEST_URI'];
$cookie_market = $_COOKIE['market'];
if (isset($_COOKIE['market'])) {
switch ($_COOKIE['market']) {
case 'city1':
echo $modx->sendRedirect('city1/',array('type' => 'REDIRECT_HEADER'));
break;
case 'city2':
echo $modx->sendRedirect('city2/',array('type' => 'REDIRECT_HEADER'));
break;
case 'city3':
echo $modx->sendRedirect('city3/',array('type' => 'REDIRECT_HEADER'));
break;
default:
echo $modx->sendRedirect('city1/',array('type' => 'REDIRECT_HEADER'));
break;
}
} else {
if ( ($record->country_code == 'US') and ($cookie_market == '') ) {
switch ($record->region) {
case 'TX':
$ip_market = 'city1';
header("Set-Cookie: market=$ip_market; Path=/; Expires=".gmdate('D, d M Y H:i:s \G\M\T',time()+720*60*60));
echo $modx->sendRedirect('city1/',array('type' => 'REDIRECT_HEADER'));
break;
case 'FL':
$ip_market = 'city2';
header("Set-Cookie: market=$ip_market; Path=/; Expires=".gmdate('D, d M Y H:i:s \G\M\T',time()+720*60*60));
echo $modx->sendRedirect('city2/',array('type' => 'REDIRECT_HEADER'));
break;
case 'CA':
$ip_market = 'city3';
header("Set-Cookie: market=$ip_market; Path=/; Expires=".gmdate('D, d M Y H:i:s \G\M\T',time()+720*60*60));
echo $modx->sendRedirect('city3/',array('type' => 'REDIRECT_HEADER'));
break;
default:
$ip_market = 'city1';
header("Set-Cookie: market=$ip_market; Path=/; Expires=".gmdate('D, d M Y H:i:s \G\M\T',time()+720*60*60));
echo $modx->sendRedirect('city1/',array('type' => 'REDIRECT_HEADER'));
break;
}
}
geoip_close($gi);
}