Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

Creating Different Versions of the Same Page (variants)

0 (0 Likes / 0 Dislikes)
Hello, and welcome back to Drupal and Panels. Now we're going to talk about how you can create several different versions of the same page, using the Variant system in 'Page Manager'. In this case, we have the homepage of our website that's currently showing a two-column layout. On the right-hand side, we're always showing people an article. But on the left-hand side, you get different content if you're logged in, than if you're logged out of the website. If you're logged in, you can see an Advanced Search at the top of the page, followed by a list of who's online at the bottom. But if you're logged out, all you'd see here was an advertisement. Well let's say that our designer came up to us and explained that the advertisers really wanted that ad to hit our entire audience, not just people who are logged out. And so she's come up with a new layout for us to implement, for people who are logged in. This layout has three columns; and we now need to put the advertisement on the right, the article in the centre, and the additional content of the Search box and the list of who's online in the left. But, she still wants for logged out users to use the previous two-column layout, with the article on the right, and the advertisement on the left. So now we need to find a way to make the same page show two different layouts under different circumstances. This would be pretty tricky using the Drupal theme system in blocks but it's very straightforward in Panels. We're going to start by modifying our existing panel. We use the 'Contextual Administration' link on the the top-right to edit the panel, and this pops us into the 'Content' section of the 'Page Manager' interface. From this interface, we can look at this wireframe and tell that this is definitely a two-column layout. But we can also look on the left-hand side, and see that we have one variant, named ;Panel'. That's not a very useful name, especially if we're going to be adding additional variants that are also Panels. So I usually start by re-naming my variants to something that more closely matches what they're actually going to be doing. Since our two-coloum layout is going to be used for anonymous users, let's re-name this variant; 'Anonymous'. Variants can be re-named under the 'General' section. Here, you can see that the Administrative title of our variant is 'Panel'. We're going to change this to 'Anonymous'. We're going to leave everything else the same, and click 'Update and save', and now on the left-hand side of the page, you can see the variant has been re-named 'Anonymous'. Now we're ready to go ahead and add a new variant for authenticated users. We're going to use a Wizard, and we're going to start that Wizard by clicking the 'Add variant' link, top-right. Clicking this link will first ask us for the name of our new variant. We're going to call this one 'Authenticated'. It'll ask us what type of variant we want; for now we're just going to use 'Panel'. We'll talk more later about different types of variants. It'll also ask us if we'd like to add any optional features, like: selection rules. We definitely want to add a selection rule because this will help us determine when our new variant will be used and will be shown to people. We're going to click 'Create variant' here to start off the Wizard, and you'll see that the first step of this Wizard will ask us to configure those selection rules. These work a lot like the 'Visability' settings we added to our individual content panes. So we're going to add one here for 'User role'. We're going to decide that our current user, the one that's looking at the page, needs to be authenticated, and that's how we decide when this variant should be shown to that user. We'll click 'Save' and continue on to the next step. The second part of the Wizard asks us to choose a layout for our new variant. So, here we're going to choose a three-column layout, instead of two. We'll pick a fairly simple one, and click 'Continue'. The next section asks us to choose the panel settings. So, here again is an interface where we can define our Administrative title for our variant. This is where we also get the option to disable the Drupal blocks in regions provided by our theme, and here we can also choose to change the 'Renderer'. So, if you have a page where you think your administrators would like control over that content, for example, here; this is our front page, you might want to change the 'Renderer' to the in-place editor to make their experience doing that a little more straightforward. Now we'll click 'Continue', and now we've gotten to the 'Panel Content' part of the Wizard. Here, we're going to first remove the title because our previous homepage did not have a title. And then we'll need to add the content to each section of the page. On the right-hand side, we're going to add the advertisement, which is in a group called 'Custom blocks', and it's a block called 'Ad'. We'll just drop that one straight in. In the centre column, we want to add that article. That article was an 'Existing node', its title started with 'D', I believe it was this one. We'll link the node title to the node, leave the links to read more, and set the 'Build mode' to 'Teaser'. Now, on the left-hand side we'll add on additional information. The first thing was a widget for the Advanced Search form. We'll leave all those options as 'Default' and drop them in. The second thing we wanted to add was a list of all the currently online users, which is shown under the 'Activity' category called 'Who's online'. Drop that one in too. So now we have all of our content in place. So we need to create the variant. After we click that 'Create variant' button, you'll notice that on the left-hand side we now have a variant here for 'Anonymous', as well as one for 'Authenticated'. If you look at the 'Content' tab for the authenticated variant, you can see we're definitely in a three-column layout. And if you look at the 'Anonymous' 'Content' tab you can definitely see that that is a two-column layout. So before we do anything else, we need to update and save. Now, you might think that since we've added an 'Authenticated' variant for the homepage since we're logged in, and authenticated, that if we were to go to look at our homepage right now you'd see that three-column layout. Unfortunately, you'd be mistaken and this is a really common mistake to make when using variants, with Panels. It's really important to get the order of theses variants correct. You want the 'Authenticated' variant, which is more specific to be listed before the 'Anonymous' variant, and the reason for that is because these variants are all executed in a series of statements. So if the first variant should pass, the second variant is never even looked at, and as it turns out in this case, we have not added any selection criteria to our 'Anonymous' variant. And if you look carefully at the 'Selection rules' tab, it says here that with no selection criteria, that test will always pass. So if you have a variant with no selection rules at the top of your list of variants none of your other variants will ever be displayed. So it's really important to re-arrange these so that your tests with selection rules happen first. They need to come before the variants with no selection criteria. So in order to re-order your variants, there's a link at the top-right, here, called 'Reorder variants'. We'll click on that link and you get a little drag-and-drop interface where you can grab your 'Authenticated' variant and move it above, in the list, your 'Anonymous' variant. If we click 'Update and save' you can see on the left-hand side that those changes have become permanent. And now, you can see your 'Authenticated' variant, with its selection rules is listed before the 'Anonymous' variant with no selection criteria. So if we now go back to the homepage, you'll see the three-column layout. It's also really important to make sure that the 'Anonymous' variant is working. So, in order to test that, we'll go ahead and log out. We're expecting to see the two-column layout with the advertisement on the left. And there it is. Stay tuned, and we'll go through another way to create a variant that's even easier than the one we just saw.

Video Details

Duration: 7 minutes and 58 seconds
Country: United States
Language: English
License: All rights reserved
Genre: None
Views: 31
Posted by: drupalizeme on Oct 25, 2012

Panels and the Page manager module allow you to create different versions of the same page (called variants) under different circumstances. In this lesson you will learn how to build two different versions of the content on your home page. People who are logged in to your site will see a different home page than people who are not.

Caption and Translate

    Sign In/Register for Dotsub to translate this video.