It's possible to make conditional fields on views without using any additional module like views php.
In this example, we're going make the path for node title automatically link to node path, a url link and a file path, depending on the content type. Note: this is just an illustration of concept which can be changed depending on the requirements.
Example
Type | Paths |
---|---|
node path | /content/node-title |
url path | http://www.drupal.org |
file path | /sites/all/files/this-file.pdf |
Content Types
- Create 3 content types, ex. News, News URL, News PDF
- On News, fields: title, body
- On News URL, fields: title, field_url (link field)
- On News PDF, fields: title, field_pdf (file field)
Add Sample Contents
- On News: Node Title (title), Some Text.. (body)
- On News URL: URL Title (title), http://www.drupal.org (field_url)
- On News PDF: PDF Title (title), upload a pdf file (field_pdf)
Views Configuration
- Create a view, block or page
- Add the fields, Content: Title, Content: URL, Content: PDF
- Add additional fields, Global: Custom Text, Content: Path
- Arrange the above fields to:
- Content: PDF
- Content: URL
- Content: Path
- Global: Custom Text
- Content: Title
Fields Configurations
- Content: PDF
- Exclude from display
- Formatter: URL to path
- check hide if empty
- Content: URL
- Exclude from display
- Formatter: URL, as plain text
- No Result Behavior, put [field_pdf]
- Content: Path
- Exclude from display
- Rewrite Results, check Use absolute link (begins with "http://")
- Global: Custom Text
- Exclude from display
- Text: put [field_url]
- No Result Behavior, put [path]
- Content: Title
- uncheck, Link this field to the original piece of content
- Rewrite Results: check Output this field as a link, on path, put [nothing], check Use absolute path