Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By hip on
I mean define a view to show some fields but, in case one of them (not mandatory) is empty, then show a different field?
And any tweaks instead of doing it from the module panel?
Thanx in advance.
Comments
Just bumping it up.
Just bumping it up.
Spanish Drupal - www.4tres.com : Desarrollo de sitios, páginas web y aplicaciones para Internet eficaces y especializadas en Sevilla.
Related: What if the field is null?
Related: What if the field value is null? I would like to exclude it from the list. I would have thought I could add a filter to exclude it from the view, but since I have chosen this field to display in the view, it has disappeared from the list of available filter fields. Why is this? Anyone suggest a workaround?
Well, I'm not sure wether
Well, I'm not sure wether this will be the same case, though a similar solution might work for both.
In my case if 'field A' is empty then in the same column (table view), should appear 'field B'
Spanish Drupal - www.4tres.com : Desarrollo de sitios, páginas web y aplicaciones para Internet eficaces y especializadas en Sevilla.
Bumping it up
Bumping it up again. Let's give it one more try.
curious as well
I'm looking into this as well. I have a situation where I'm creating a list of web links. If a proxied web link is available, I want to use that, if it's not, then I want to use the unproxied web link, but I can't see an easy way to implement such conditional logic through straight-up Views.
Looking for this, too
I'm looking for exactly the same thing and bumped into this thread.
I have a (grid block) view where long node titles look bad. So I've defined an optional field for that content type called "short title". I want my view to display the short title field if it is not empty, else the node title.
Any pointers?
override views template
You are going to have to override the view's template at some level to add custom "if this is empty then show this" logic, you can find out the info from click the "Theme: Information" link for the view you are editing. This can get tricky as it depends on the 'Style' of the view (table, grid, etc) and possible the associated row style of the view.
I've done it this way with
I've done it this way with views theming.
It's a bit tricky but doable.
Figured out how to do this using the "computed field" module
Solved, FYI:
Note that I am a Drupal and PHP newbie, so use this at your own risk. Works for me.
Here is my example:
The first if-statement is needed because in a newly edited node, the node title is empty and would return null.
Notes:
The computed field will have no value for existing nodes, so nothing will show up in your view. You will need to update those (edit and save). Does anyone have a good way to update multiple nodes?
looks interesting
without doing any research, looks interesting, although the explicit call to node_save() looks a little scary to me. When is that executed? Has the edit / add node form been validated before your node_save() is called?
Honestly, I don't know
Honestly, I don't know this. I picked this up from the code snippet collection, specifically this one: http://drupal.org/node/149232
Would be interesting if a more expert user happens by who could clarify.
_
I'm no expert, but what about something like this:
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
_
Hi,
I think I have a similar issue but don't know the best solution.
I have a CCK integer field that is a simple set of No/Yes radio buttons that only an administrator can see on a particular content type (this is so we can flag it as having a product/file download attached - don't ask, long story). Values are 0|No and 1|Yes....I'd like to be able to display a link/button on my view results if the value is set to 1|Yes.
I get the impression there could be two ways to do this...one is to follow the above method (but not sure how) and add a Computed CCK field that says....if field X is set to yes then write the link/button code and then I can use this in the view.
The other method I've seen mention of is to possibly edit the views-view-fields.tpl.php template....or at least that's how I understood it to be.
I guess my question would then be, is it possible to do and if so, which would people recommend as the better option? I thought that maybe the computed field option would be safer with regards to module updates, would this be the case?
Many thanks for any help as it's always greatly appreciated
_
I usually do this type of thing with computed fields-- very flexible method.
_
Sort of suspected you'd say that WorldFallz after your previous help that gave me my first insight into computed fields ;)
I've managed to get it to do what I want. But not being too hot at this could you/anyone just confirm for me that the following is OK;
I love the way that it'll contstruct the url in it's aliased format, awesome stuff.
Thanks
_
Yep--- looks good. computed_fields are extremely useful for all sorts of things. The views counterpart is http://drupal.org/project/views_customfield.
drupal is awesome-- but then I'm biased. ;-)
you are not biased...
You are extremely intelligent :)
(You've answered more questions for me, mostly not something I even posted, hope someone pays you to do Drupal stuff so you stick around!)
_
lol, thanks. drupal is part of my day job, but even if it wasnt i'd still be hanging around- i'm just that geeky, lol.
As Joachim has mentioned - it
As Joachim has mentioned - it can be done via Views templating and then just PHP to check the desired conditions.
I just did a simple thing - to show a "promotion" next to a product, if there is a promotion set for that product.
Here's my approach to it:
Created a CCK radio button with only 1 option available "promotion"
The CCK automatically sets another option "N/A" - which, if selected returns empty (in PHPTemplating).
Then in my View and the Display for these products I added the Field (in Fields) for Promotion (name of the field in my case: field_promo_yesno), Label set to None.
Then click on Theme: Information link
Here I see the name of the field and the possible template file names. In my case I selected views-view-field--field-promo-yesno-value.tpl.php
And here is the content of this file :
Saved the file, uploaded it to my Drupal current template folder.
After that I click on the "Rescan Template Files" button (it's on the same page, where you go after clicking the "Theme: Information" link)
If my new mini-views-template is successfully found by Views - the bolded file name for currently used template for my desired field will change from views-view-field.tpl.php to views-view-field--field-promo-yesno-value.tpl.php
After that I enabled/disabled the value for some product and tested it on the Views generated page (my products catalogue) - everything is OK and working :)
No way for me to make it
No way for me to make it working :( I created a computed fields like this:
Included it in a View but the result is always null. I also included a default value in the Database Storage Settings and the result is the same.
A few questions:
- There could be any issue related to Data Type of stored data and Format of View field?
- Should the Format of View field be Computed Value or Text?
- Is the instruction
if (!$node->nid) node_save($node);
really necessary in this case or not?- How can be possible that even setting a default value in the Computed field nothing appears in the View field?
Thanks in advance :)
FYI the code for all this is
FYI the code for all this is slightly different in the D7 version of Computed Fields.
webform with conditional fields and views and views attach
I have a site setup (d6.17, cck, views, conditional fields, views attach - plenty of other modules) (system setup: linux OS, apache 5.2.x, plenty of php_memory, mysql)
The owner wants to allow for users to add a taxonomy term, without 'tagging' (this almost always results in content forking).
So my solution is that the content type has a conditional field which is ticked yes/no box (other*) when ticked (*yes) then there is a webform displayed with a submission for a new taxonomy term. I was thinking of embedding the webform with views attach to the certain content types (*edit page: build modes).
Then in theory the user will be able to submit a new taxonomy term if the relevant one is not available.
Can anyone advise on a better solution?
Why isn't this a module?
Views If Then module or something. This: http://drupal.org/node/945268 looks like the same issue, as does this: http://drupal.org/node/869286. I'm not adept enough yet to build a module, but it seems like there's enough demand for sure.
Field conditions within Drupal 7 Views
I understand that field output in Views 2 cannot be managed conditionally in the UI. Can it in Views 3 (D7)? So far I’ve hit a wall, suggesting it cannot.
I’m building a D7 site for our German Shepherd rescue group and need to solve the problem of presenting fields conditionally within views. Here are the bones of the scenario:
Query pulls all unadopted dogs from DB to display in a mini-pane. Conditional fields needed:
Managing both of these manually is possible but would offend the DB gods.
My thought was to do another query to identify the new dogs, for example, and join that with the unadopted dogs query to add the necessary ‘new’ field. Same with ‘Foster Needed’. I guess that’s not what Views Relationships is for, huh. Is there some way to accomplish this that I’m not seeing?
In searching I’ve come across a PHP solutions outlined in this thread and the CSS solution in jakepyne’s tutorial. I have even considered the terrifying power (power for a noob like me to screw up) of Computed Field and Views PHP. I guess what I’m hoping for is the moron solution as, until I started with Drupal, I thought PHP was that new drug the kids were on and CSS was the acronym for and embarrassing skin condition.
Any help with a simple solution to what seems to be a common problem would be greatly appreciated. I am hoping that D7 offers some functionality in this area that I simply haven’t stumbled upon.
Just a run down of the
Just a run down of the solutions...
-Computed Fields solution posted by mpromber seems like a winner, I'm gonna try it. My only gripe is that I'd rather keep all logic stuff within Views, and just leave Content Types alone.
-Compound Fields (not 'Computed') for Views can do the same thing, without PHP coding, but the module is only available for Drupal 6. I used it once to give importance to a manual thumbnail for image nodes, worked like a charm. No programming required.
-Custom Field for Views is useful too but all it will give you is a spot to do PHP code as a Views field. You'll still have to do PHP code to do something, although it would be similar to above.
-People mentioned doing PHP in Views theme files, that can work too, but again you have to code and plus it just adds to your files in the theme folder. Personally I try to avoid as many files as possible in the themes folder.
Don't forget to mention -
Don't forget to mention
- Views If Empty
I needed to display a field depending on the value of the checkbox field (boolean). To get it working properly I had to specify a value for the "on" state of the checkbox in my field settings (I used "yes").
Furthermore, it's pretty easy to fork this module to make it do all other kinds of conditional rendering.
For example, I didn't want the "empty field" shown at all. Unaltered, the module shows the "outputfield" when the "emptyfield" is empty, otherwise it shows the emptyfield. But it always shows one of both. I only wanted the emptyfield to control the visibility of the outputfield. So, I altered the code in views_ifempty_handler_field.inc (render() method) as follows ...
to
I hope this helps ...
Problem
I used this which is great except that it gives me an error for the first entry in my view and doesn't show the conditional field. The error is
Notice: Undefined property: views_handler_field_field::$last_render in views_ifempty_handler_field->render() (line 114 of /home/smarkit3/public_html/www.intnews.com/TTIBuyersGuide/sites/all/modules/views_ifempty/includes/...).
Which I presume is related to the code alteration. Any ideas for stopping this? I'm using D7.
Thanks
This might come in handy:
This might come in handy: http://drupal.org/project/views_conditional
Another way
Using this solution https://drupal.org/node/1935092 helped me.
Handy
A table display of products (Ubercart) the 'Add to Cart' only show if the value of the 'In Stock' field is greather than 0, wonderful.
No results behavior
If there are two fields that you only want one of them to show => add both fields to views, and then exclude second one from display (check "Exclude from display"). Now in first field go to "No results behavior" setting and enter the "Replacement pattern" of second link. (Just remember that second field should be upper that first one in list in order to see it as Replacement)
Now every thing's OK. Whenever first link is null the second appears instead...