phía dẫn xuất hiện a liên kết in a New Tab trong Views không buộc phải the PHP Filter
I had a task. It seemed simple enough. It involved a link field with a title and a url (created by the liên kết module) và a single on/off checkbox field. The checkbox was a toggle for whether the liên kết should mở cửa in a new browser tab/window.
The task was to lớn create a Views page that displays an edit icon which links to the url and conditionally opens in a new tab/window based on whether the “Open link in New Tab” field is checked...without using the PHP filter module.
I went down several paths - Views hooks, Views preprocess functions, template files, template.php, creating a new link formatter, etc. There was a nice brick wall waiting at the end of each. Then I was introduced by co-worker Derek Deraps to lớn an interesting twist in Views. It was all possible using the Views GUI.
The premise is to output đầu ra a liên kết that opens in a new tab using the Rewritten Results of the “Open liên kết in New Tab” field & a link that opens in the same tab through the “No Results Behavior” of the “Open liên kết in New Tab” field. Genius.
Let’s phối up an example view to lớn demonstrate:Create a Views page and địa chỉ your link field. Set the formatter lớn “URL, as Link” & exclude from display.Add a Global: Custom text field. This will be our link that opens in a new tab when the “Open in New Tab” checkbox is checked.Exclude from displaySet the html for your image:
Save the view & view the page. Voila! The link with the “Open in new tab” box checked will xuất hiện in a new tab/window.