Hi gang,
New to Drupal and loving it (I was previously a DIY PHP/mysql junkie). I have a question for the Views gurus.
My scenario:
I have a list of nodes I am returning via Views. Two fields needed are [title] and [alternative_title]. [alternative_title] will often be empty, but [title] is always required.
I would like to have views output something like this under the one column:
[title] ([alternative_title])
However, the ( and ) need to be hidden if [alternative_title] is empty.
I have placed [title] first and hidden that field. I then "rewrote" the output of [alternative_title] with the above code example. It works, however, we get empty brackets if the [alternative_title] field is empty. Using the "Empty text" field for [alternative_title] to display only [title] if the [alternative_title] field is empty was no help, because "Empty text" does not interpret fields unlike "Rewrite the output of this field" does. Otherwise that would have been a good option.
Any suggestions for how to do this?
Kind regards,
Jason
Comments
You should configure the
You should configure the "alternative field" prefix and suffix with " ( " and " )". After doing that you should exclude this field from output and put it before the title field.
At this point you can rewrite the output of the title field and add the [alternative_field] token.
--
by FiNeX
FiNeX.org
Siti Web Vicenza
Ha! Wow. I really couldn't
Ha! Wow. I really couldn't see the forest for the trees. I can't believe I didn't see that.
Perfect. Thank you Finex, I feel embarrased now! :-)
Cheers,
Jason
Don't worry, and good luck
Don't worry, and good luck with your project :-)
--
by FiNeX
FiNeX.org
Siti Web Vicenza
don't worry! And good luck
Don't worry, and good luck with your project :-)
--
by FiNeX
FiNeX.org
Siti Web Vicenza
prefix?
Excuse jumping in on this long after the fact, but what prefix where? I have just the same problem but I'm still stuck in the forest.....
On the field settings
On the field settings
--
by FiNeX
FiNeX.org
Siti Web Vicenza
Wow I've been looking for
Wow I've been looking for this answer for forever, really. Thank you, thank you, thank you, FiNeX!
Brad, Prefix is located in the field setting's REWRITING section:
Add a field to your view and configure it's view options
In the REWRITING section, click the checkbox for "Output this field as a link"
Put the replacement pattern you want in the Link path.
Put the other stuff you want in the Prefix text and/or the Suffix text.
Check Hide if empty (I also check Count the number 0 as empty)
Exclude from display and save.
Add another field and add the replacement pattern from the one above into REWRITING section.
Hope that helps!
I get the concept, but this
I get the concept, but this isn't working for me.
1) With nothing in the link path, the prefix/suffix don't show.
2) With something in the link path, the entire thing is rendered as a link.
I'm not sure how this worked for you.
Which version of Drupal and
Which version of Drupal and Views are you using solona?
Drupal 6 and Views 2.
Drupal 6 and Views 2.
Try stripping the HTML tags
Try stripping the HTML tags option and see if that stops it from rendering as a link.
Thanks for the suggestion
Thanks for the suggestion. I got it working. Trying to do something a bit different with jQuery and it works (in browsers that like jQuery anyway).
Thanks
So simple a solution but not very apparent. Thanks FiNeX!!
Conditional Rewrite Revisited
I have a problem with something I know should be extremely simple. I can get the text version described above to work just fine. What I think should be EASILY done, yet stumps me, is this:
No matter what I try to substitute with rewrite, it either ALWAYS shows up (even when there is no field value) or it breaks the line. I can get it to work perfectly with plain text.
You'd think Boolean page decorators would be a really common and easy thing to do, but I haven't seen a solution anywhere (without rewriting templates).
views_customfield
This module may help you, it allows for php.
http://drupal.org/project/views_customfield
Read this thread to get a better idea of usage.
http://drupal.org/node/467190
Thank you!
Thanks for your response. I installed the module and will commence playing around with it with help from the usage post. So far it seems more painful than it needs to be. :-)
Did you figure out how to replace a boolean value with graphic?
djmmuir - I am trying to accomplish exactly the same thing now. Were you able to solve this? I'm going to look at views_customfield next, but have just started and hope to save some time. Thanks!
Use the rewrite functionality
Use the rewrite functionality to set the field's class and rewrite the output to blank. The result will be
<div class="field-value"></div>Now you can apply background with CSS (and proper margins for offsets).