Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: [Tutorial] Function Extras  (Read 1949 times)

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
[Tutorial] Function Extras
« on: March 05, 2010, 04:41:55 AM »

This will be a tutorial about the cool and unique function called extras.  Extra is a function that allow a content block to be shown on your template, where ever you call it. As of 1.7, extras are goverened by Extra Groups (or Groupings), so you can have multiple Extras goverened by one Group.

A History Lesson:
In the beginning there was... wait hold on, wrong history... Ok Extras began as the left and right content blocks back in 1.3 & 1.4, where it then merged into 1 content block being able to be shown on any user created category or page in 1.5 and 1.6.  Thi swas ok but if you wanted more, you either needed Doug's mod that gave 2/3 extra blocks or you could have used my mod that eventually went into 1.7....

The Basics:
The main site doesn't go into Extras, so I will get into it now. In your template the Extra function is called like so:

Code: [Select]
<?php extra(); ?>
Quote
** Note - If I recall, this has been the same call since 1.5.
 

By default, you can start adding extra content to this placement in the Extra Content admin panel.  Extra Content looks just like the Admin Content panel, with different options. We can allow our extra content to show on any user made page or category, or even placed in the subcategories of the selected category.  

Quote
** Note - Please pay attention to the Category/Pages drop downs. They give further notes on what areas the content is shown.  Please review before saving.

Quote
** Note - If you want to have content shown on the base pages use my fix here: http://snewscms.com/forum/index.php?topic=7996.0

With 1.7, the Extra has a default Group called 'extra' (unique huh?).  If the function call doesn't have the group name noted in the function call, the system will always revert back to the base Group 'extra' - please keep this in mind.  

Now how do we manage groups?
In settings, you need to enable the Extra Group in settings/content. Go back to the main Admin page, and you should see the Extra Group links abouve the Extra Content links.  Here we can add, view the group call, and edit the Group.  If you want to change the Extra Content to be placed in a different Group, this needs to be enabled as well or it will not show.

Quote
** Note, if you edit an existing Group, make sure you update it in the template.


We can call the extra in our template like so:
Code: [Select]
<?php extra('group-name'); ?>
Let's use Extras:
Ok, if you already applied the fix above, then create a new Extra Content block for the Contact page. I chose to make mine with some alternative contact information:
Quote
Alternatively, you can Contact me here:

Jason
1234 Hemingway Drive
Cliffs on the Hudson, NY, 10911
914-356-1000

Now, in the template, we are still using the base extra call, but I want to style it without hacking the core.... Ok, extra allows this:
Code: [Select]
extra(GroupName (str, default NULL), AllowDiv (0/1), ClassName (default NULL), IDName (default NULL));The first argument is the Group name.  The last 3 are Allowing the Div; 0 for no, 1 for yes. Then add your class or id name to be applied for each content block within.

So for my extra call, i will do this:
Code: [Select]
<?php extra(''1'extra'); ?>And my HTML now looks like this:

Code: [Select]
<div class="extra">
<h3>Alternative Contact</h3>
Alternatively, you can Contact me here:

Jason
1234 Hemingway Drive
Cliffs on the Hudson, NY, 10911
914-356-1000
</div>


Ready for another application of extra?

Now with the Web 2.0 style, footers are becoming bigger and having more columns added to them, perfect for a tutorial!

1. Let's create a new Group called pre-footer

2. add it to our template before the footer div:
Code: [Select]
<div id="pre-footer">
<?php extra('pre-footer'1'ftr-col'); ?>
</div>

3. Create 3 Extra Content blocks for the pre-footer Group (look in customization to allow the group choice)

4. Add some (REALLY QUICK) CSS
Code: [Select]
#pre-footer {
clear: both;
width: 96%;
margin: 0 auto;
}

.ftr-col {
width: 30%;
padding: 0 10px;
float: left;
}

5. Roughly, you should have something like this:
« Last Edit: May 02, 2010, 08:47:02 AM by nukpana »
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [Tutorial] Function Extras
« Reply #1 on: May 01, 2010, 05:03:14 PM »

I missed that tuto. Good shot Jason.

I never been able to make it work on articles in categories or sub-categories. It just works on pages. I certainly have a goof in my Core.
Gonna check that is seems really useful.

Thanks for the tips. 8)

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: [Tutorial] Function Extras
« Reply #2 on: May 02, 2010, 08:58:43 AM »

I think so Sven as cats and subcats should work fine on a default install. Assignments to individual articles is not base functionality, but I am sure it can be done with some hacking - thought I would rather see a mod like Custom Fields for that purpose.
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [Tutorial] Function Extras
« Reply #3 on: May 02, 2010, 02:57:49 PM »

Yes you're right Jason.
My sNews had a buggy code on that part, now fixed.
I think I'm gonna play around with this very very cool feature.
Thanks again for the light. 8)