Hello,

I have recently installed the events module and I am looking for a way to simply add the link "add an event" that is in "create content" directly into the page that displays the events calendar.

I know how to move menus, etc., I am just looking for a way to nest this menu directly within the module itself, sort of an intuitive way for users who are looking for events to add them directly from the events page.

I am sure this is fairly easy but I would like to accomplish this without using blocks.

Can anyone help a brother out?

Comments

skywalker2208’s picture

Create a page-event.tpl.php file and add the link to the appropriate place in the file.

MikeMoirano’s picture

As a non-coder, I have no idea what that means.

Would the contents of page-event.tpl.php be a copy of page.tpl.php, but with the modifications?

I don't even know how to call that link, so this may be tough.

xenefox’s picture

Im not familiar with the event module however the first two things I'd try is to modify the module file itself. (In the module's folder)

Or implement the Custom Links module which appends links to nodes.

modul’s picture

I suppose that page.tpl.php is the place to be.

First, take a look at the url when you add an event. It will probably be something like http://www.yoursite.com/?q=node/add/event.
Then, open your page.tpl.php. Try to figure out the proper location for your link.
If you are within a <?php ..... ?> part of your file, you could issue some code like this, but without the ?php ? tags:

if (arg(0) == "node") {
  echo "<a href=\"?q=node/add/event\">Click to add an event</a>";
}

If you want to place the link in a non-php part of your page.tpl.php, you'd write something like this:

<a href="?q=node/add/event">Click to add an event</a>

If you want to finetune the exact circumstances in which to show or not to show the link, you'd have to work a bit more with the arg() function, within a php zone. Arg(...) reads the current url in your browser url window. In "http://www.yoursite.com/?q=taxonomy/term/2345", for instance, arg(0) would be "taxonomy", arg(1) is "term" and arg(2) is "2345".

MikeMoirano’s picture

Thanks for this incredible response. This really explains a lot, but I have one more question.

My events is a link from my front page using nice menus, so in my page.tpl.php file, the only place that refers to 'events' is through print theme('nice_menu_primary_links'); .

So I am guessing I am adding the if arg statement within that php, but arg(0) would just be event or whatever is appropriate???

Thanks for this extremely helpful reply.

modul’s picture

Hi Mikemoirano,

I have no experience with NiceMenus, but I don't suppose that really matters. Whether it is by NiceMenus or something else, there will always be a link issued, which you should be able to read in the message bar at the bottom of your browser, or, once the link has been accessed, in the URL window on top of your browser. Get hold of that url, and mess around with it in your page.tpl.php. And to see what arg() you need, just play a bit with arg(0), arg(1), arg(2), arg(3) etc.

The "print theme(...)" line only shows the link in accordance with your theme, it doesn't actually "make" it. You are at liberty to show it anywhere you want in your page.tpl.php.

MikeMoirano’s picture

Thank you so much. Surprisingly, as someone who obviously has no coding expereince, I just figured this out, and now it seems like so much more makes sense.

You rule.

modul’s picture

Coding is not the world's most difficult activity. It looks impressive sometimes, but with some trial and error you can go a very long way. And the nice thing about Drupal is that you can dabble with base level code, for instance in your .tpl files, without having to touch the modules or (heaven forbid) the core. My site is becoming quite complicated, with varying access levels for various user groups, with a lot of tricky taxonomy stuff, but I have Not Once changed a module file (except maybe for some official patch).

One good advice: never throw away a bit of working code just to experiment with something new. Comment it out, or make a copy or something, just make sure that you can always return to something that worked.

And one more: Never Ever code directly into a block. It is Very Easy to make your whole site completely inaccessible, also to user number 1, with one line of erroneous code in a block. If you want to put something in a block, Always try it out in a node first, until it works. Only then stuff it in the block. Forgetting a ";" in a block has once cost me an entire evening of nervously staring at a blank screen, and I had to get it out by digging into the database tables with PHPMyadmin. Don't make that mistake, and always code in a node first. If things go wrong there, only the node will be ruined, and your administrative access will still be there.

Another good advice (hmm, I sound like granny :-) ): make a function which checks if you are the administrator of the site or not,

function you_are_the_boss() 
{
  global $user;
  if ($user->uid == 1) {
    return true;
  } else {
    return false;
  }
}

Then, for instance in your .tpl files, you can play around:

if (you_are_the_boss()) {
  echo "Only the big boss can see this experimental code. It may even break the site, but my visitors won't even notice.";
} else {
  echo "You are obviously not the big boss, so I'll show you only things which work.";
}

I use that function at least 10 times a day, whenever I'm trying out things. I keep it in my settings.php, although that may not be according to The Book.

And for the rest: have fun!!

MikeMoirano’s picture

Thank you so much.

I appreciate all the advice I can get, and have thus so far avoided experimenting with php when it is now becoming increasingly necessary, so granny away!

You really are making this easier for me.

Thanks again

MikeMoirano’s picture

So, let's say that I wanted to combine the advice you gave me, meaning I would like to display the link but only to users who are logged in, is it possible to put both the if argument and the echo statements into one?

I create the function (module?) and then in my page.tpl, where I have called the argument "events" from before, can i just add

if (you_are_a_user()) {
  echo "<a href="node/add/event" class="calltoaction">click here to add an event</a> etc. etc.";
} else {
  echo "please log in etc. etc.";
}

to the same statement? can you have two functions to one if statement?

modul’s picture

Sure you can have two functions to one if statement. Actually, if-constructions can be as complicated as you want them. What I wrote, was just bare-bones.

I don't know about the "class" part, but for the rest your code is going into the right direction. One thing: when you echo quotes which are not string delimiters, you have to "escape" them. So, the quote right after "echo" is OK, because it starts a string, but the quote after the = requires escaping, because it is part of what you want to echo. The rule of thumb is: if you would use a quote in straight HTML, you have to escape it in PHP. Escaping is done with a backslash \ before the quote.
The result is then:

if (you_are_a_user()) {
  echo "<a href=\"node/add/event\" class=\"calltoaction\">click here to add an event</a> etc. etc.";
} else {
  echo "please log in etc. etc.";
}

By the way, for a very useful and step-by-step PHP course you could go to: http://www.w3schools.com/php/default.asp . It's about 100 pages long. You can skip the part about installing PHP, and when you reach halfway, you qualify as a "PHP coder" :-)

If you want all technicalities about PHP and the zillions of functions which come with PHP and all its extra libraries, just spend a couple of centuries browsing through http://www.php.net .