Pagelist view.php with specific layouts based on attributes

Permalink
Hi everyone... Thank you in advance for anyone that can assist here.

I need to create a pagelist that has 3 different layouts depending on the pages attributes selected when creating the page.

Basically...

if 'events' is selected as my custom page attribute, the pagelist view.php renders it as:
<div style="height:200px;width:400px;">content here</div>

if 'news' is selected as my custom page attribute, the pagelist view.php renders it as:
<div style="height:100px;width:200px;">content here</div>

if 'other' is selected as my custom page attribute, the pagelist view.php renders it as:
<div style="height:300px;width:200px;">content here</div>

I am trying to make jQuery Isotope work as a pagelist so in my basic understanding 'if' commands are necessary.

My understanding of PHP is VERY basic so if anyone is able to help, please pretend that you are talking to an idiot :-)

 
jero replied on at Permalink Reply
jero
You would probably do something like this

global $c;  // may not be needed - should be the current page object
$event=$c->getCollectionAttributeValue('event');
switch ($event){
    case 'news':
         ?><div>......</div><?php
          break;
    case 'whatever':
         ?><div>......</div><?php
          break;
    default:
         ?><div>......</div><?php
          break;
}


where 'event' is the page attribute handle.
mobius2000 replied on at Permalink Reply
Hi Jero,

Thank you for taking the time to reply, much appreciated.

I'm not sure I am following your response correctly. I have placed the following as my view.php...

<?php 
/************************************************************
 * DESIGNERS: SCROLL DOWN! (IGNORE ALL THIS STUFF AT THE TOP)
 ************************************************************/
defined('C5_EXECUTE') or die("Access Denied.");
$pages = $cArray;
$th = Loader::helper('text');
//$ih = Loader::helper('image'); //<--uncomment this if generating thumbnails below
//$nh is already set for us by the controller
$showRss = false;
if (!$previewMode && $controller->rss) {
   $showRss = true;
   $rssUrl = $controller->getRssUrl($b);
   $rssTitle = $th->entities($controller->rssTitle);
   $btID = $b->getBlockTypeID();


And created a page attribute titled 'event' (select list) with the following options 'news' and 'whatever' however the resulting pagelist only shows them style for the default option.

I am certain I have made a foolish error based on my lack of PHP knowledge but I was hoping you might be able to point me in the right direction when you get a spare few minutes.

Richard.
And probably not surprising it doesn't achieve the
jero replied on at Permalink Best Answer Reply 1 Attachment
jero
Might be my fault:

$event = $page->getAttribute('event');
switch ($colour){


change $colour to $event

and you probably want to fire this code up immediately after the foreach ($pages as $page):

and of course add a closing <div> just before the endforeach

Try this (untested) example
mobius2000 replied on at Permalink Reply
Perfect, thank you sooooo much Jero... Playing with this has also given me a better understanding of the attribute calls throughout the rest of C5 too. Thank again.
jero replied on at Permalink Reply
jero
No problem - have fun!
freestylemovement replied on at Permalink Reply
freestylemovement
hi mobius,
i'm also very interested in getting this feature working in my website, and am a bit rusty on the PHP. it appears like you got it working, i was wondering if you would mind posting the final version? it would help me out a lot.

from the last time i set up a c5 website, a few things changed. i was just able to add in page attributes (i made 3 categories, big medium small)

now i just have to figure out how to properly change this file.
is this example just a customized view.php loaded as a block template?

and where do you call on the script so it loads best for the whole site?

again, thanks in advance for anything you can clarify, would love to see the product too!
mobius2000 replied on at Permalink Reply 1 Attachment
Hi Freestyle movement... First off, I am a very weak PHP coder so if anyone notices anything completely wrong, I am very sorry. I got the outcome I needed with the below content.

I have attached my page_list view.php so you can see what I did.

If you take a look at the view.php file you will see lots of:

case 'Tall': ?>
<?php break; case 'Small no text': ?>


This searches for the value of your custom attributes. For the purpose of this I'm going to presume you know how to make custom attributes (let me know if you don't).

The view.php I uploaded has lots of calls to attributes but I'll focus on the one I think your referring to.

Up in the attributes section of the view.php you will see the following:
<?php  foreach ($pages as $page):
// get the event attribute
      $size = $page->getAttribute('size');


Size is the handle I gave my custom attribute that determines the size of the box on the page. Within that custom attribute I added the values Tall, Small no text, Small, Medium, Large, Image Only (the attribute is a select box).

Then we simply need to make the rendered content dependent on each of those values.

<?php  switch ($size){
   case 'Tall': ?>
      <div class="article_box tall">
                       This box will appear is 'Tall' was selected in the custom attribute 'size'                    
                </div>                      
   <?php
   break;
   case 'Small no text': ?> 
      <div class="article_box small-no-text">
                   This box will appear is 'Small no text' was selected in the custom attribute 'size'
                </div>
   <?php
   break;
   case 'Small': ?> 
      <div class="article_box small">


This is a striped down version of the area found within the view.php.

I hope this has helped in some way... You can view the final outcome of what I was trying to achieve here:http://www.mugsu.org.au
freestylemovement replied on at Permalink Reply
freestylemovement
thanks for the quick response!
site looks great, even if you say you're new :)

so, i'm pretty sure i know what's up with attributes, using the dashboard
making a new handle and adding values ( your handle is 'size' and values are 'tall' etc)

correct?

now, as i patiently wait for C5 to install, i just would like to clarify,

where did you call on the script for the isotope.js file?
is it in the global header.php file, or in the block, or somewhere else?

i hope i can get this to work, i would really love to have a front page with animated sorting and different size posts.. fingers crossed..

thanks again for your help.