I'm really new to this, so you'll have to bear with me.

I have a view (non-calendar type) that lists events. Each event is a daily log. I have 'another' view, which 'is' a calendar view, that shows them all in a calendar format. The purpose of the non-calendar view is to show 'all' the events in a list.

At any rate, my view lists two things: title and event date ([field_date_value]).

What I'd like to do is turn that event date into a link that would open the calendar for that event to a specific day.

I figured this was a good time to learn how to use tokens. Besides the CCK, Views and countless other modules I have installed, I recently installed the 'Token Custom', thinking this would help me make my own tokens. I was pleasantly surprised when viewing the existing tokens that it 'appeared' as though there were some formats that already existed that I could leverage.

That brings me to "Output this field as a link" in a View. I figured this would be my moment of glory, where I could put a relative link to my calendar and pass it something like:

my_calendar/[yyyy]-[mm]-[dd]

Well, that failed heinously, and not because it would, in theory, have used the year, month and day when the node was created, but because it 'literally' spit out those values as is and did not replace them.

Realizing I now had 2 problems, I decided to try to resolve the first: why wasn't my token being replaced? I tried [nid] next, everything has that. Still, it literally put [nid] in my links.

So questions are:

1. Are the only tokens I can use in "output this field as a link" in a View those which are listed below? Namely, the current field and any preceding field?
2. Assuming I can use any other token, why would it not replace [nid] in my second test?
3. Assuming I can use other tokens, are there tokens predefined for me upon creating a new Date field (using Date in conjunction with the CCK)? If so, what are they? I saw some listed like [field_date-yyyy], is it that? Would it be "my_calendar/[field_date-yyyy]-[field_date-mm]-[field_date-dd]"?

Any help would be appreciated. Love the product and community modules thus far, just having a hard time getting some "how-to" answers, and not finding any straight forward documentation for some of this.

Comments

WorldFallz’s picture

1. Are the only tokens I can use in "output this field as a link" in a View those which are listed below? Namely, the current field and any preceding field?

This is a brand-spankin new feature, but i believe you are limited to the tokens listed. If others were available it would say so and the token module would likely be listed as a views module dependency.

If you need a token that's not there, simply add the field for it and check the "exclude from display" option. It should then be available as a token.

notebene’s picture

Being new at this, it raises the question "how do I add a new field for token", as you stated in the last line?

I know how to add fields to the view, but I'm not sure how to set it to the value of a token? I see the 'change output of field' allows me to do HTML, can I do PHP in there as well?

WorldFallz’s picture

You have to add the field to the view like any other field. Then select the "exclude from display" option so it won't be shown. Then, provided it appears above the field in question, it will be available as a token in the "replacement patterns" option box.

notebene’s picture

Sorry I wasn't clearer. I understand how to create the field above the field I want to use it in, but it seems like I'll end up chasing my tail, because 'that' field will suffer from the same problem - not having access to the tokens I need.

Specifically, it looks like a calendar view can take another parameter in the form of yyyy-mm-dd that would open it to a specific day view. What I was trying to do was get a field (or token) formated in such a way that it would output the date field I created on my node. I'm using Date with the CCK and Views, and created a new content type called 'Event', and gave it a new field called 'Date'. I now have a field I can reference as [field_date_value].

How would I create a field 'above' my date field, for the purpose of reformatting it's output as a link, such that my field that wants to display as '03/12/2009' writes out as '2009-01-12', so I can generate the link as "my_calendar/2009-01-12', which would open up 'my_calendar' on that day?

So, let's set the tokens aside. Is there a way in Views that I can take a field value, and using PHP, Javascript, whatever, reformat it completely?

markabur’s picture

if you're talking about reformatting the date field, you can do that with a custom date format, 'Y-m-d'

notebene’s picture

Ok, I hadn't realized the association between 'Site Config/Date and Time' and my available formatting options for a date in my views. Added a new custom format then added a new format that used that format, cleared the cache, and there's the pick. Perfect!

One small problem. When using [field_date_value] in either 'rewrite the output of this field' or 'output this field as a link', it spits out this:

/some_calendar/<span class="date-display-single">2009-03-01</span>

How do I remove the span tags (and more importantly, why is it even adding them)?

WorldFallz’s picture

It adds them so you can style the field easily with css (i'm pretty sure all fields have it). If you want to remove it, you'll have to theme the view.

notebene’s picture

Thanks, off to review that next!

WorldFallz’s picture

Is there a way in Views that I can take a field value, and using PHP, Javascript, whatever, reformat it completely?

I think of two ways. You can add the field just to the view with the http://drupal.org/project/views_customfield module or you can add the field to the node with the http://drupal.org/project/computed_field module which will then be available to views. Which you choose depends on whether or not you want the field to appear on the node as well as the view.

notebene’s picture

I'll take a look at these modules and give them a test drive, thank you.

nessumsara’s picture

I'm using Drupal 6.10 with Views 2. I'm trying to make the Title of the node in a view link to an attached file in a cck file field I've associated with that node. I

- added the title field above the file field
- checked "Rewrite the output of this field" for the file field
- entered "[title]" for the text
- checked "output this field as a link" for the file field

Problem is that the only available replacement pattern is [field_attach_fid]. When I try using that in the Link Path it spits out all of the information for the file field including div tags. I'm wondering why I can't use [field_attach-filefield-filename], [field_attach-filefield-filepath], or [field_attach-filefield-view]?

I also tried modifying the title field instead, but ran into the same problem with replacement patterns.

danny_joris’s picture

Hmm, I think you have the same issue as me, but you solved it by doing something else. I still have my problem. I want Tokens to make the links I want in Views. More here: http://drupal.org/node/518808#comment-1814620