I have a view that displays nodes called events.
The view has 3 columns
Date - Title - Taxonomy Term.
The view shows all event nodes unless I supply a taxonomy term as an argument. This is all working fine.
I can reference event/live-bands and events/djs without problem.
I have setup the Taxonomy Term field to "Output this field as a link" and I've placed "events/[name]" in the Link Path field under "Output this field as a link"
This works, however, the output is upper case with spaces.
events/Live Bands and events/DJs
Is there any way to modify the output this field as a link so that it is lowercase and replace spaces with a dash so that it matches the arguments that I have created?
The other question is whether I'm going about what I'm trying to do the right way.
I want to list all events, and allow the user to "filter" events by clicking on the term name in the table row instead of using an exposed filter at the top of the column.
Thanks.
Comments
Comment #1
dawehnerI think there should be just one question per issue. Create a new one for the second.
Make a new template for the taxonomy term field.There you
$output = str_replace(" ", "-", strtolower($output));Comment #2
merlinofchaos commenteddereine's answer is the only way to do it; Views doesn't have a way to transform tokens, so you'll need to do it at the theming layer. Note that if you're using pathauto to get aliases, you might try linking to taxonomy/term/[tid] which will get translated properly by the linking system, but it's not clear to me if your events/... link is an alias or another view.
Comment #3
cookiesunshinex commentedThank you for the response. After a little research on how to theme a view field, I created a file called
views-view-field--eventsview--name.tpl in my theme directory, where "eventsview" is the name of my view.
This works perfectly on the taxonomy term name column of my view. It now inserts a "-" where spaces previously were, and all case is changed to lowercase.
However, the output of this column is no longer a hotlink. In other words, it's not clickable.
Is there a way to:
1. Keep the text in the column properly capitalized and spaced.
2. Keep the text as hotlinks (clickable).
3. Modify the links so that they link to lowercase locations and if there is a space in the link, the space is converted to a "-"
Here's what I have
This works to make all the case lower case, but keep the hotlinks. So it appears that str_replace is removing the hotlink. However both the text in the view as well as the hotlinks are changed to lowercase.
Comment #5
jon nunan commentedWhile the above works fine, if the pathauto module is installed could we mimic its behavior for tokens used in paths?
Something like the following in the 'render_as_link' function in 'views_handler_field.inc' :
Sorry, don't have patch tools on this box.
EDIT: actually this breaks more than it fixes, the code above needs a ui element to choose when its active. Otherwise using the above to create links to other views that use 'taxonomy terms' as arguments will be broken.
Comment #6
venusrising commentedMerlin-
When using the vocabulary name field to link to a view of the type [name] (all is working well) can the text for this also be transformed? I have searched high and low and we have views created for each vocab so it has a landing page so the method works well it is just when printing it on the frontpage view the link shows in caps. We have tried the methods below but it does not work in the view...field etc tpl. The other thought we had was using mod rewrite to force lowercase but would rather do it without if possible.
We are using current Drupal, Ctools, Views etc. I know this was from an older version but it was all we could find similar after hrs.
Thanks
Comment #7
venusrising commentedComment #8
Letharion commentedThis question has a general answer in comment #2.
If you have a different question, please open a new issue.
Comment #10
roxflame commentedI figured out a solution that will create a link field that is displayed with spaces, but writes the link path with dashes.
I had to think outside the box and bent my brain a little coming up with this one.
Add 2 copies of the taxonomy name field in views.
Create views-view-field--yourview--name.tpl
In this file add:
This will open a relative link with the replacement dashes added into the path.
Then on the second field check the "Rewrite the output of this field" box and add:
[name]</a>This will insert the text without the dashes and close the link you opened with the first field.
Ideally set the 2 fields to inline to remove extra un-needed tags and you should be set!
Comment #11
kaynen commentedI was looking to do this exact same thing, and after messing with it at the theme layer, I thought there had to be a better way. I was also not sure about combining a solution with the theme layer and a custom view field like @roxflame's solution. I ended up using Views Customfield with this custom php code:
I then excluded the php code field and used it's token on a field below to output it with a couple other fields as a link. Hope this helps someone.
EDIT: As noted by @twstdelf, the above solution only works within a term view, not a node view.
Comment #12
Anonymous (not verified) commentedThanks @kaynenh - I agree this is a better solution.
Comment #13
Paul Lomax commentedHere is one that doesn't require any extra modules.
In your view, add the Term: ID and Term: Name fields, change the output of Term: Name so it reads
<a href="[[TERMLINK-[tid]']]">[name]</a>, exclude the Term: ID field from being displayed, you only need it as a token.Then in your theme, or a module add:
Basically creating your own token then replacing it in the final output, simple!
Comment #14
ghazlewoodGreat idea in #13 Paul! Thanks for the tip
Comment #15
digitalfrontiersmediasimpler still, in CSS (your selectors may vary):
.field-type-taxonomy-term-reference .field-items
{
text-transform: lowercase;
}
Comment #16
Josephnewyork commentedI wrote this to have php tokens in my views:
Obviously replace [TEMPLATE] with your theme name and clear your cache.
With this, in your view, you can use php tokens like so:
<a href="/category/[php:strtolower:[name]]">[name_1]</a>The token structure is as follows:
[php:FUNCTION_NAME:ARGUMENT:ARGUMENT:ARGUMENT...]
Currently you have to pass one argument, but you can rewrite it to have all php function arguments optional.
Works like a charm.
Comment #17
gunwald commentedJust for the record: As Drupal 8 uses twig for its templates, you can achieve this by rewriting the views field results with the option »Override the output of this field with custom text«. Use the replacement pattern with the "|lower" option:
{{ field_name|lower }}That's it.