How to Control the Visibility of the Promo Code aka Promo Block (Brief intro to the Dolphin Key and Template System)

jtadeo posted 21st of April 2009 in Community Voice. 15 comments.

When you visit a standard Dolphin 614 install, you will see a lead graphic that cycles through a set of images. It looks something like this:

How to Control the Visibility of the Promo Code aka Promo Block



However, there maybe times where you don't want the promo code or promo block to show up on the front page of your Dolphin site. One of the easiest ways to to that is by opening up the page_1.html file located in templates/tmpl_uni and deleting or commenting out the "__promo_code__" key so that it looks like this:

__include _header.html__
<!-- __promo_code__ -->
__page_main_code__
__include _footer.html__

Optionally, you can also replace the "__promo_code__" with HTML and bluntly add whatever you want such as a .swf file, gif, jpg almost anything that can be parsed by the browser. There is a complete tutorial available on my site on how to do this and also how to work with keys.

However, what if you wanted the lead graphic to show for visitors and not for members? This tutorial shows you how to do just that.

You can control the visibility of the lead graphic with a few lines of code. It's actually very easy. In this tutorial, you will be working with:
1. index.php
2. page_1.html located in templates/tmpl_uni/

We will also be making an additional template page based on the page_1.html template page.

Brief Overview of the Dolphin Templates and Keys

The index.php layout is controlled by several items found in the Dolphin framework. In this tutorial, we will take a look at the page_1.html file. This file delegates what shows up on the page that uses it. For example, the index.php file uses the page_1.html file. If we open up the index.php file, you will see this line of code:


...code above...

$_page['name_index'] = 1;

...code below...

You can see the number "1" just after the variable declaration. This basically is telling the index.php to use the page_1.html file for its template. The page_1.html file looks like this:

__include _header.html__
__promo_code__
__page_main_code__
__include _footer.html__

You will notice that it contains nothing that resembles either PHP, CSS, HTML or JavaScript. Well, that's because it uses a system specific to Dolphin. It uses a key system to deliver and target content to wherever it may be placed. In the case of the page_1.html file, it basically says to show:


1. the header as denoted by the __include _header.html__ key.
2. the lead in graphic as denoted by the __promo_code__ key.
3. the main body of the page (in this case all the blocks as defined by what we place in the page builder) __promo_code__ by the __page_main_code__ key.
4. the footer as denoted by the __include _footer.html__ key.


You will find more examples of the key system at work at my www.boonexnerd.net Dolphin tutorial site.

In this tutorial, what we want to do is to NOT show the __promo_code__ key. To do this we need to set a condition. The condition we will use is guest vs. member. For example, when a guest or visitor is looking at the home page of the site (index.php) we will show the lead in graphic like this:


How to Control the Visibility of the Promo Code aka Promo Block



When the guest/visitor has logged in, they gain member status, we will hide or not show the lead in graphic so the main page will now look like this:


How to Control the Visibility of the Promo Code aka Promo Block

Instructions -How to Hide the Promo Code Block When a Member is Logged In

This is a step-by-step on how to set up your index page to control the visibility of the lead in graphic aka the promo code block.


Before you begin, make sure you back up your files.


1. Open up the page_1.html file located in templates/tmpl_uni/ and resave it as page_1000.html or whatever number you want as long as it doesn't already exist. In our example, I used page_1000.html because it doesn't exist in my current install.


2. Open up the page_1000.html file and delete the "__promo_code__" key. So that it looks like this:

__include _header.html__
__page_main_code__
__include _footer.html__


3. Save the file.

4. Open up the index.php file located in the root of your site. You will see the following code:

...more code above...

require( BX_DIRECTORY_PATH_ROOT . "templates/base/scripts/BxBaseIndex.php" );
require( BX_DIRECTORY_PATH_ROOT . "templates/tmpl_{$tmpl}/scripts/BxTemplIndex.php" );


check_logged();

$_page['name_index'] = 1;
$_page['header'] = $site['title'];
$_page['header_text'] = $site['title'];
$_page['css_name'] = 'index.css';

...more code below....

What we want to do is replace this line:

$_page['name_index'] = 1;

So that it now looks like this:

//jt note - show the promo graphic if NOT logged in - START//
$theMemberID = (int)$_COOKIE['memberID'];

if($theMemberID == 0){
$_page['name_index'] = 1;
}else{
$_page['name_index'] = 1000;
}
//jt note - show the promo graphic if NOT logged in - END//


What we just did was set the guest vs. visitor condition. One of the first things we needed to find out was if the person is logged in or not. We do this by finding out the value of the member id. In this particular example, we are using the value of 0 to mean that they are not logged in and the system considers them a vistior. Here's the code that does that:

$theMemberID = (int)$_COOKIE['memberID'];


The above will give you the member's id.


We then run a conditional test. We want to find out if person viewing is logged in or not. So we do this:

if($theMemberID == 0){
$_page['name_index'] = 1;
}else{
$_page['name_index'] = 1000;
}


Depending on the results of the test, it will either show the page_1.html template or the page_1000.html template. If they are a member and logged in, it will show the page_1000.html template. This means it will no longer show the lead in graphic or the promo code.


I know of a few other ways to do it. One of them is just a line of code. But this one gives you a brief tour of the Dolphin key system.


There is an entire set of functions found within the Dolphin code that can be used to really customize your site to whatever you want it to look like. We've just taken a simple example of how to do that by working with the promo block and key that controls its visibilty.


In invite your comments. Please try it out and let me know how it goes.


...sip...

 
Comments
·Oldest
·Top
Please login to post a comment.
Great works like a dream...thank you
Chrixxi
really simple....great tutorial !!!...thx
edwinjarvis
Fantastico jtadeo!

Thank you. Your tutorials have helped me so much.
DeeEmm
Perfect tutorial, very easy to follow and explains what's going on.
Michi_A
Thank you for this tutorial. Very usefull!!!
jtadeo
@ all, thank you :D

You can also get more info at http://www.boonex.com/trac/dolphin/wiki/GenDolFAQs#HowcanIcreateacustompageformysite

This one shows how to make a custom page for your site. There are other good links there too. For example "Creating a search engine friendly new Dolphin page". You can find that at:
http://www.boonex.com/trac/dolphin/wiki/NewPageCreation#CreatingasearchenginefriendlynewDolphinpage

There are a lot of answers now as the Dolphin community grows. I see more turst Dolphin sites will get better and better as people learn how to make their own custom pages and templates.
Diddy
Thank you sooooooo much. Nice done and easy to understand.
Synergy
As always well done, thanks.
qammar
good one like all your other tuts.
amakhehla
perfect, thanks for sharing all your knowhow, the world is a better place :)
MissMorgan
Brilliant, easy to do and really makes a big difference to the members. Thanks for existing jtadeo..this is not the first time I have turned to you for clever ideas.
Jhazzi
You're great! I'm greener than green, newer than a newbie, dumber than dumb with this stuff and I did this!


Forever grateful for the help you've provided! Thank you!
yossi
How can we do it with V7? I see they change the structure of the HTML
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.
PET:0.10215997695923