Hello,
I am trying to accomplish what I think is a simple task.
Here it is:
Example of the URL:
1. I have a homepage that I would like to change dynamically based on the URLs string (dc=apples)
2. I am using a view to create a banner. The view puts the banner together by combing a number of fields (main headline, subheadline, image, button text, button link, etc.). So, lets say that I want the main headline to change based on the URLs string. This is what I am trying to accomplish.
3. I went into the field, and selected the "rewrite results" and the "rewrite the output of this field" and placed the following code into the area:
<style>
.dynamic-content {
display:none;
}
</style>
<!-- Default Dynamic Section -->
<div id="default-content" class="dynamic-content">
This is the default content
</div>
<!-- Dynamic Section 1 -->
<div id="apples" class="dynamic-content">
I like apples
</div>
<!-- Dynamic Section 2 -->
<div id="oranges" class="dynamic-content">
I like oranges
</div>
<!-- Dynamic Section 3 -->
<div id="bananas" class="dynamic-content">
I like bananas
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
// Parse the URL parameter
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
// Give the parameter a variable name
var dynamicContent = getParameterByName('dc');
$(document).ready(function() {
// Check if the URL parameter is apples
if (dynamicContent == 'apples') {
$('#apples').show();
}
// Check if the URL parameter is oranges
else if (dynamicContent == 'oranges') {
$('#oranges').show();
}
// Check if the URL parameter is bananas
else if (dynamicContent == 'bananas') {
$('#bananas').show();
}
// Check if the URL parmeter is empty or not defined, display default content
else {
$('#default-content').show();
}
});
</script>
Well, as you can guess, it is not doing what I want it to do...it will not parse the code.
Can anyone help me?
Thanks