Drupal 6: Displaying Node on Homepage

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
jessSchn's picture

Hi Guys,

I've been out of the Drupal world for a few months and I'm glad to say I'm back. I'm working on a Drupal 6 website that is using a template page to layout the homepage and the content on the Homepage is statically controlled by the template page.

I've been tasked with changing a section of the homepage so a user can login to the CMS and then use the CMS to update this specific section of the homepage. (Hopefully that makes sense). I'm brand new to Drupal 6 (more familiar with Drupal 7) and I haven't been able to find a way to implement this CMS editable section on the homepage.

Any advice or guidance would be appreciated.

Comments

several options

_rohn's picture

I'm sure many more capable than myself can offer better solutions, but I think it depends a lot on what the content is that will be controlled by the content editors... one solution might be to add a CCK field to the node type and then print that out in the template. Another could be to use a module like Node as Block.

How far from static will this content deviate? In other words, one month might it be an image, another a view, and another just text?

Content

jessSchn's picture

Pretty much this content is very minimal and will be very similar to these lines from month to month:

<div style="padding-bottom:0; padding-top:5px;">
<p>What you should spend <br/>on automation.</p>
<p><a href="" target="_blank">Contain the Costs of Workload Automation</a><br>
Live Webinar: Wednesday, March 28</p>
</div>
<h6 style="margin-top:5px;"><a href="" target="_blank">Register Now!</a> </h6>

The person that will be editing this content in the CMS does know some HTML.

An easy quick, toss it out

_rohn's picture

An easy quick, toss it out there and see if it sticks, solution could still be the CCK field (a text field) and then just output whatever they put in there (without getting into discussions about verifying the integrity of the HTML, etc)

Now a disclaimer: I have also, it's apparent, worked on the site you're now working on.

Knowing that you already have a content type for upcoming webinars I'd truly give some consideration to playing off that with a view. Perhaps using the "sticky" setting to determine if a webinar should break rank-and-file and be listed out of date order, if that's a requirement. (take a look in the git history and see what's been there previously) Your content editors already have to enter information about the upcoming webinars in the site, this would allow them to not have to do dual-entry and they wouldn't have to worry about individually updating the homepage when the webinar shown there has past.

Here is what I would do...

JBack's picture

Hey Jess,
Here is what I would do to accomplish this, it is simply another solution, and I am not saying it is the end all be all.
I will be throwing a lot at you, so I apologize in advance.

First and foremost, you need CCK. So install that module.

Next create a content type and call it "Promoted Content" or something similar and create the proper fields that you need.
I would highly recommend removing the body field and creating a CCK field called "body" as it will make things easier.

Next create a region in your template.info for a block to include this "promoted content".
(You may need to enable the block in /admin/build/block/list/mytheme in order for the block to show up)
Create a file in your template directory for the block (block-myblock.tpl.php).
In your front page template (page-front.tpl.php), include the block ( print $myblock ).

Now, open the block file (block-myblock.tpl.php) and paste in your html that you need for formatting the output of "promoted content".

Clear the theme registry cache (or all of them) to make your block appear on the front page.

Next comes the fun part, create a promoted content node using your cool new promoted content type, and put in some test text so we can make sure everything is working. Then save the piece of content.

Then, in your block file use the drupal api command:

$promotedContent = node_load (myPromotedContentNodeId, null, true);

This will load the promoted content node object into your block and you can grab the information from the $promotedContent variable to get whatever fields you like and print them in the block. (you can use var_dump or print_r to see what is contained in the object)

The added benefit is now you have a node that your editors can edit to their heart's content.

Hope I didn't loose you with all of that.
If you need any help with any of the steps feel free to contact me at jwbabc@comcast.net.

Good luck! Once you get the hang of it, themeing in Drupal is really powerful!

You may hate me for this

lorlarz2's picture

You may hate me for this, but you could always use an iframe and put an instance of
this thing in it: http://mynichecomputing.org/sampWIKI/ (once you go to wiki page there
is a link to the downloadable kit)

This is what 4 months experience with Drupal but 13 years experience with javaScript can do to
a guy. Nonetheless, it would work and it would work very quickly.

[ Similarly, my chat could be installed in Drupal -- which has apparently nothing but a horrible chat
module, Here: http://mynichecomputing.org/chatpopup.html ]

Try This

wylbur's picture

Create a region in the home page template.
Add the region to the info file of the theme.
Create a block with only your html content.
Assign the block to your new region.
Move the CSS to your theme css file. Use the classes from the block to target the CSS to your block.
Now your user can update the block content each month.

There's probably as many

jerdavis's picture

There's probably as many answers for this as there are users of Drupal, some good and some bad. It all depends on the goals, so starting there and working out to a solution is the approach I'd recommend.

Based on your description and the copy of the block you provided, here's how I'm interpreting this:

The customer has monthly (or more frequent) events (webinars) that they want featured on the front page of the site. They want to feature one (or more) events with a link to register.

With that in mind, I'd start by:

1) Create an event content type
2) Add a date field (date, cck modules)
3) Add a mechanic for registration: signup module if on-site, link field if you're linking to something like a webex presentation for the signup (link module, cck).
4) Create a view (views, views_ui) with a block display to list the latest (1? 3?), published events that occur in the future. Select the fields (title, date, body, link, etc) that you want to display or use a formated teaser display as output.

You can place the block on the page by editing the template and adding a region. If there are other similarly hard-coded "blocks" on the page, you may want to make those dynamic as well if it makes sense for their use and the client's goals. Once you've added the region and placed the block you can decide how much theming work you need to do to approximate the current look of the static content. You can override different levels of Views templates if needed to tweak markup, or create a teaser template for the event node that handles the custom markup.

Likely you can do everything you need to by using the standard markup output by views and adjusting the CSS to style each element. A field based view is going to give you a lot of markup you can hook into to tweak styling.

Creating an event content type gives you a lot of other flexibility too. You could display the upcoming events in other ways on other parts of the site. Relate upcoming events to other relevant content, create a calendar of events using Calendar module, relate events to each other, handle registration on the site itself, add payment handling for paid events, the list goes on.

Of course if not all (or most of) the things featured in this block are events then you may need to adjust your thinking on the content type. Also if the client wants more control over which one shows up when (beyond latest published) you'll need to consider different methods of curation such as using the promoted flag, a custom flag from Flag module, a node queue, etc.

Given what you said about the client not knowing HTML, and the fact that the current hard coding is an issue I'd try to steer clear from other solutions that are similarly inflexible. If you have to hack on a lot of *.php files or, heaven forbid .module files - then you're taking flexibility away from the solution. If you hard code a node_load in a template file, you're bypassing a lot of the systems that are in place to help both you and the client maintain the site.

Hope that helps! If you're at the meetup Wednesday feel free to grab me after if you want to go over this in more depth.

Jeremiah

Spot on!

_rohn's picture

hi Jeremiah,

as usual you are spot on! this functionality had been in place on the homepage on the site Jess is working with (I had the pleasure of working on it previously), though less with regions that you're suggesting (I like it though!). Instead of just an event type though, she's got event "header" and an event "detail" content types. The header type has all the non-changing information for sporadically scheduled events (description, location, cost, etc), while the detail has the specifics (date, signup links, etc).

Jess, if you look back in the git history for the site you should see the homepage as it used to be, with the views_embed_view code in the node-home_page.tpl.php (you can get the view from there since I don't recall the specific name, and I'd be surprised if the view itself has since been deleted). You'll need to change the existing view to reformat it to the new requirements, of course.

I'm planning on being at the meetup Wednesday as well... I can try to fill in some of the corners of how the site is currently structured as Jeremiah gives you the good bits :)

Rohn

Thank you All

jessSchn's picture

Thank you all for the comments and suggestions on this.

Rohn, I did see the old code and technically it does work - but it doesn't give the writers the freedom they would like with this spot. Which is why I'm in here messing with it.

I'll give a couple of the suggestions a try and hopefully I'll make it in to the Drupal Meetup tomorrow.