theme bulder cheatsheet / quick ref..

5 users found helpful
I think bryanlewis asked this at some point.. but I'd love to see a one pager list of stuff you can easily do inside of template files...

Obviously this would be the basic couple of lines of php that a template file needs along with the block area calls.. but what else might it include?

How to limit the # of blocks a block area will display.

How to reverse order the blocks in an area.

How to display specific values from the collection object..

what else? in my mind, these would mostly but cut and pasteable examples... (my personal favorite way to 'learn')
frz
View Replies:
frz replied on at Reply
frz
this should be on there
<?php
global $c;
if ($c->isEditMode()) {
 //Do something
}
?>
frz replied on at Reply
frz
Try $c-&gt;getCollectionName();

Message:
It's a little counterintuitive, since there's no obvious reason for calling the page object $c (and what's a collection, anyway?) But this is the way it's done.

<?php
print $c->getCollectionName();
?>


The $c variable should be in the scope of your theme without having to do anything to import it.
jibrilmuller replied on at Reply
Does anyone know how I could print the page title of the 1st level of the current page i'm in.

So basically if i'm in products, I always want to write products regardless of which sub page i'm in.

Any ideas?
xs2 replied on at Reply
xs2
maybe there is an easier way, but this one seems to work. I took it from an autonav template.

<?php
               //this will create an array of parent cIDs 
               $inspectC=$c;
               $selectedPathCIDs=array( $inspectC->getCollectionID() );
               $parentCIDnotZero=true;   
               while($parentCIDnotZero){
                  $cParentID=$inspectC->cParentID;
                  if($cParentID==0){
                     $parentCIDnotZero=false;
                     $inspectC=Page::getById($selectedPathCIDs[count($selectedPathCIDs)-2]);
                     echo $inspectC->getCollectionName();
                  }else{
                     $selectedPathCIDs[]=$cParentID;
                     $inspectC=Page::getById($cParentID);
                  }
jordanlev replied on at Reply
jordanlev
jibrilmuller replied on at Reply
Your a champ, that worked perfectly
frz replied on at Reply
frz
global $u;
if ($u -> isLoggedIn ()) {
echo "Logged in!";
} else {
echo "Not logged in!";
}
bryanlewis replied on at Reply
bryanlewis
This is great! Should we include simple stuff too like how to fetch style sheets? ...

<style type="text/css">@import "<?php echo $this->getStyleSheet('main.css')?>";</style>
bryanlewis replied on at Reply
bryanlewis
<?php $this->inc('elements/file.php'); ?>
bryanlewis replied on at Reply
bryanlewis
<?php Loader::element('header_required'); ?>
bryanlewis replied on at Reply
bryanlewis
<?php
$a = new Area('NAMEITWHATYOUWANT');
$a->display($c);
?>
mario replied on at Reply
mario
i've noticed that if you include some special characters in the subdirectory name such as a dash or dot (- .) whatever parses it doesn't seem to like it.

so:

<style type="text/css">@import "<?php echo $this->getStyleSheet('superfish148/css/superfish.css')?>";</style>


not:

<style type="text/css">@import "<?php echo $this->getStyleSheet('superfish-1.4.8/css/superfish.css')?>";</style>


seems to work fine with getThemePath though.
Tony replied on at Reply
Tony
Just got back from the Theme Throwdown:
http://www.concrete5.org/community/forums/chat/announcing__theme-th...

thought I'd post a recommendation for how to prevent problems when using a third party theme that has loosely scoped css rules. A lot of the free css templates out there tend to add some pretty greedy style properties to standard elements (like padding or margins on all li or div tags for example). This causes some major issues with the way stuff in the concrete toolbar and popups are rendered. An easy way to fix this is to wrap the template markup with a <div id="page"> or <div id="wrap"> tag (just inside the <body> tags), and then in your main.css and typography css, append the #page or #wrap to each css rule, to limit its scope.
Hope that helps somebody out there.
ScottC replied on at Reply
ScottC
another problem I had was cascading styles that started from the body tag and were more specialized on children div and again on each element.

like: the body set everything to light gray, #container added <a> styles, main div changed text to dark grey, side div kept the light grey from the body tag. From Object oriented-esque principles this is nice, but tinyMCE finds it hard to pick up these styles in this way.

Also images close to the top will be pushed down by the toolbar, but the background image will not, so you have to do a:

if ($cp->canWrite() && cp->canAddSubContent){ echo a style like body background-position: 0, 60px; to move the background down with the rest of it.

Also doing something like this:

if($c->isEditMode()){ echo('<div style="height:60px;"></div>');} to create space between "areas" so you can click the element below the area without it being overlapped by something else.
frz replied on at Reply
frz
i love the idea of protecting concrete5's CSS from the themes css more absolutely, at least on themes we feature in our marketplace. I think tony has hit the nail on the head with his approach here and it should be adopted as a standard must on the theme's checklist.
brennaH replied on at Reply
brennaH
I'm very new with concrete5 but I've already found this method helpful for pulling custom page attributes to "pre-populate" a design with page data:

$myString = $c->getCollectionAttributeValue('my_attribute');
print $myString;
Tony replied on at Reply
Tony
If you've got some markup that should only be displayed if an area has blocks within it, you can do something like this:

<?
$area = new Area('AreaName');      
if ($area->getTotalBlocksInArea() > 0) { ?>
   <div class="someClass">Some Title</div>
   <div class="someOtherClass">
   <? $area->display($c); ?>
   </div>
<? } ?>
olay replied on at Reply
olay
So if the code to get the page title is

<?php 
print $c->getCollectionName(); 
?>


Could anyone tell me what i would need to lift attributes from the page above the one you are on? (the parent page)

This could be useful if you wanted to automatically generate a section header which appeared on subpages below that one)

thanks
Tony replied on at Reply
Tony
first you'd get the parent page's collection/page object

$parentPage = Page::getByID($c->cParentID);

...and if you wanted it's attributes, you could do this:

$parentPage->getAttribute('myAttributeHandle');
olay replied on at Reply
olay
– thank you, hopefully helpful for the cheatsheet / quick ref. too
suzykaploozie replied on at Reply
suzykaploozie
I just posted in the themes forum asking if a document with these php elements existed and now I find this...

Not everything I need is here, but this is a GREAT help!

You guys rock :)

Thanks <3 !!!

Suzy
epursimuove replied on at Reply
An an attempt to recreate a Dreamweaver template This is what I have used:

Identify the template parameters, our has a lot of cruft associated with breadcrumbs, so I am ignoring those because I have replaced them with an autonav element.
<!-- TemplateParam name="_someName_" type="[boolean|URL|text|number|etc...]" value="" -->

You will have to take any of the TemplateParams you want to use, and create a Page Attribute (under Pages and Themes > Page Types), for ease, I made the handle the same as the TemplateParam. Keep in mind that a 'checkbox' attribute can be used in place of a 'boolean' param.

To insert the attribute anywhere, just put
<? print $c->getAttribute('_someName_'); ?>


To optionally display something (based on a boolean attribute). I am leaving the Dreamweaver TemplateBeginIf in for clarity, so you know where to put the php code...
<?php $splash = $c->getAttribute('splash_div');
  if (isset($splash)) {
    print '
     <!-- TemplateBeginIf cond="splash_div" -->
     <div id="cSplash">
     ';
    $a = new Area('cSplash');
    $a->display($c);
    print '
     </div>
     <!-- TemplateEndIf -->
';} ?>

You can also do a if(!isset($splash))...

To add the Parent doctitle and the page doctitle:
<h1><? $parentPage=Page::getByID($c->cParentID);print $parentPage->getCollectionName(); ?></h1>
 <h2><? print $c->getCollectionName(); ?></h2>


To add a breadcrumb autonav:
<?php
 $bt_main = BlockType::getByHandle('autonav');
 $bt_main->controller->displayPages = 'top';
 $bt_main->controller->orderBy = 'display_asc';
 $bt_main->controller->displaySubPages = 'relevant_breadcrumb';
 $bt_main->render('templates/breadcrumb');
?>


Hope you find this useful, i have found this kind of documentation difficult to find (at least in any concise way)
olay replied on at Reply
olay
I've created a page attribute with the handle "start date" and the attribute is a date field.

I can get it to display on my page using the following code:

<?php $date = $c->getCollectionAttributeValue('start_date');
echo $date; ?>


And this just displays it in the full form including the time (2009-06-13 21:04:00)

How can i change the date form here?

I know i need to put in ('d,F,y') – my chosen date format – somewhere but i can't work out where...

Thanks
Tony replied on at Reply
Tony
here u go:
<?php $mysqlFormatDate = $c->getCollectionAttributeValue('start_date');
echo date("d,F,y",strtotime($mysqlFormatDate)); ?>
mario replied on at Reply
mario
when you have the js in a folder in your custom theme directory:

put this in your header.php

<script src="<?php echo $this->getThemePath(); ?>/somedirectory/somejavascriptname.js" type="text/javascript"></script>
mario replied on at Reply
mario
I usually add an internal stylesheet area after the header.php include to tweak out/override the main.css styles in each Page Type layout. Of course, this can get out of control... So when you get beyond 5 or 10 style rules you might consider adding a link to a separate external stylesheet in each page layout instead.

<style type="text/css" media="all">
<!--
-->
</style>


There might be a more programmatic way of doing it as in - psuedo-code:

switch {
case1:(fullwidth){ some stylesheet }
case2:(leftsidebar){ some stylesheet }
case3:(rightsidebar){ some stylesheet }
case4:(home){ some stylesheet }
}

but it works for me as long as I don't go too crazy with many pagetypes.

mario
mario replied on at Reply
mario
pop this in your header.php under the header_required element and modfiy which html tags/classes/ids you want to target. Please note that the script needs some padding on the element to round it.

Example:

<script src="<?php echo $this->getThemePath(); ?>/jquery-corners-0.3/jquery.corners.js" type="text/javascript"></script>
<script>$(document).ready( function(){
  $('h1').corners("5px");
  $('.login_block_form').corners("5px");
  $('#someContentArea').corners("10px");
});</script>


you can download it from here:
http://plugins.jquery.com/project/corners...

documentation:
http://www.atblabs.com/jquery.corners.html...

Upload to your custom theme's directory but not the Themes directory itself.

Doesn't always play nice with divs that contain multiple floats but pretty good with single elements. Border effects don't really work in IE7 but the background effects do.

Best of all, since it's jquery, no need to link to jquery since Concrete 5 automagically does it. :)

I understand that it's a tweaked version of jquery so don't be surprised if not everything functions just like a clean install. Please correct me if I'm wrong...
chattojimnow replied on at Reply
chattojimnow
All i want is to be able to show page title and then the main content on the page about what should i be doing, IE a news or event page
I am thinking i need to create a template for page-list block but not knowing much php and kinda limited to the way concrete works im not sure of the code to use. can anyone help me with a template code?
frz replied on at Reply
frz
i think the page list block basically does that without even using a custom template, no?
chattojimnow replied on at Reply
chattojimnow
It uses the page description meta tag i want it to use a template tag instead
sschildbach replied on at Reply
sschildbach
Wow, this even works on the individual <li> header navs! Thank you Mario. There might be an easier way, but this is how I did it: if you want to put rounded corners on the individual colored tabs of the header nav, I assigned rounded corners to each <li> by assigning rounded corners in the javascript to it's created class call (found by turning on the firefox developer toolbar, or firebug, or whatever you use). Yes, I had to make a call for each tab, maybe extra code, but it worked!
suzykaploozie replied on at Reply
suzykaploozie
Is there a specific command we should always use in the nav section when we want the top nav to show on every new page created?

When my client Adds a new page, I want the top nav bar to already be there in it's place so they don't have to add it every time.

I thought $menu would do it - some times it works, some times it doesn't and I can't figure out why.

Any suggestions?
bryanlewis replied on at Reply
bryanlewis
If you add it to the default of the page type it will automatically load every new page you create.
suzykaploozie replied on at Reply
suzykaploozie
Something's not working correctly on my end then. I have it added to all my templates and everytime I create a new page, the edit box just says "Add to Menu"

I believe I'm using the correct coding:

<?php
            $menu = new Area('Menu');
            $menu->setBlockLimit(1);
            $menu->display($c);
            ?>
enque replied on at Reply
enque
The code you are using will create an editable area with the title of Menu but nothing is added to it. To have your nav on every page you need to insert the autonav block into the header.php file in the elements folder (or where your main nav should appear)
Use this
<?php
$bt_main = BlockType::getByHandle('autonav');
 $bt_main->controller->displayPages = 'top';
 $bt_main->controller->orderBy = 'display_asc';
 $bt_main->controller->displaySubPages = 'none';
 $bt_main->render('view');
?>


This will create your main nav on every page and only display the top nav and not the children. Hope this helps.
bryanlewis replied on at Reply
bryanlewis
When you have a background image in the body tag add this code.

<?php 
$cp = new Permissions($c);
if($cp->canAdmin() && $cp->canAddSubContent()){ 
echo '<body style="background-position: 0 50px;" class="' . $c->getCollectionHandle() . '">'; 
} 
else{ 
echo '<body class="' . $c->getCollectionHandle() . '">'; 
}
?>


this way the image will move down appropriately with the tool bar and not stay in place. :)
netclickMe replied on at Reply
netclickMe
bryanlewis, thanks for the follow up on moving down the background. That's a fix that will now go into all my previous and future concrete5 themes.
This fix got me an idea to customize the CMS top. I altered the code to include a banner for personalizing my clients themes. Using this single div also reduces the need for that else statement in the original snip. Here's what I did.

css
#concreteTop { 
   background: url(images/banner.jpg) repeat-x bottom;
   margin-top: 50px;
   height: 35px;
   width="100%";
}
after<body>
<?php
$cp = new Permissions($c);
if($cp->canAdmin() && $cp->canAddSubContent()) {
   echo'<div id="concreteTop"></div>'; 
   }?>
nige replied on at Reply
nige
Hi Bryan.

I have just this problem but (excuse me if this sounds thick) but where exactly do I paste this? In the head? I tried a few times in the head, body, body tag but it just blew everything away. I think Im missing something?

Do I need to reference some css class in the pasted code? I just have a plain old <body> tag with a background image in it. Do I need a class for my <body> tag as well?

Help appreciated.

Nige
jordanlev replied on at Reply
jordanlev
Take his entire code snippet (from <?php to ?>) and replace your existing <body> tag with it -- so you're replacing one line in your html (the <body>) with the 9 or 10 lines of Bryan's code.
PerryGovier replied on at Reply
PerryGovier
I use these a lot to have some things in the scrapbook, so they're editable, but not editable directly on the page. It saves people from having editable area overload.

Note: the scrapbook item has to have the name in getByName(). Also, I define an area array at the top of my templates so I can just more legible variable names. This is the code that goes at the top of my template files:
$area = array();


This one is for the logo:
<?php
$block = Block::getByName('Company_Logo');   
if( $block && $block->bID ) $block->display();    
   else echo SITE;
?>


This one if for a nav bar:
<?php
$block = Block::getByName('Nav_Bar');  
if( $block && $block->bID ) $block->display();
else{ 
   $area['Nav Bar'] = new Area('Nav Bar');
   $area['Nav Bar']->display($c);
}?>


note that if the item doesn't exist in the scrapbook, it'll just be an editable area
zoinks replied on at Reply
so, just to be clear... THIS THREAD is the cheat sheet, right? I was looking for a link to a cheat sheet, but I didn't see one. :)
webjedi replied on at Reply
webjedi
This is glorious. I am soooo close to figuring this little snippit I am writing.

In this 'page title' area (let's say)..

I am trying to check to see if there is a value in the default blank block (to see if it has been edited and thus a vlaue inserted intot the block.

If there isn't one, I want to pop the page name in that area and have it be editable if needed.

Ic an fetch the page name, and populate it in the title spot, but I cannot allow it to be editable ..

Ideas?
elyon replied on at Reply
elyon
You could create a Page attribute, called something like "Custom Title"

Then in your code you could check to see if there is an attribute value. If not, you can display the page name
dancer replied on at Reply
dancer
Nothing to see here – Just subscribing to this thread.

I have nothing to add... still a real newbie, and a bit thick in all honesty
sebastienj replied on at Reply 1 Attachment
sebastienj
Hi everyone,

I just build a basic document with some instruction found here, in templates andhttp://wiki.razrlight.com/concrete5_cheatsheet... there.

English is not my mother-language and I build this quickly. So if you find mistakes tell me about!

If you have other some nice script or other stuff this thread is the better place !

Download the attached file.
moth replied on at Reply
I found your cheatsheet via Google and refer to it often... Thanks!
suzykaploozie replied on at Reply
suzykaploozie
Thank you SOOOO MUCH! This will be an excellent source for me!

Great job!

Suzy
jordanlev replied on at Reply
jordanlev
This is great, thank you!
mario replied on at Reply
mario
excellent, thanks!
fig replied on at Reply
fig
Display content to logged in users only.

$u = new User();
if ($u->isRegistered()) {
// content here visible if user logged in //
}