I've been trying to create a View that re-writes a field (the fully-qualified path of a file, for use in a url) as part of the "src" attribute of an iframe.
I managed it only by resorting to the views_customfield module and writing the field in PHP, not (as I should have been able to) by directly rewriting the field using base Views. I would have been happy leaving it at that (using customfield) but views_customfield is not now available (if it will ever be) in D7.
The problem seems to be that Views is stripping some of the HTML in the process of re-writing the field.
The code I specified was:
<h2 class='title'>[title]</h2>
<div class="XXXEYECATCHERXXX" style="text-align:center;margin-left:auto;margin-right:auto;">
[body]
<iframe style="text-align:center;border:1px solid black;width:80%;height:600px;" src="http://www.google.com/"></iframe>
</div>
But the output code is:
<div class="view-content">
<div class="views-row views-row-1 views-row-odd views-row-first views-row-last">
<div class="views-field-body">
<div class="field-content">
<h2 class='title'>A page</h2>
<div class="XXXEYECATCHERXXX">
<p>This is a page with a spreadsheet in it</p>
</div>
</div>
</div>
</div>
</div>
As you can see, the style attribute of the XXXEYECATCHERXXX div is gone, as is the entire iframe.
Installed software:
Core: 6.20
Ctools: 6.x-1.8
Views: 6.x-2.12
I've attached the exported view I used to create the html code I quoted above.
This is duplicatable in D7:
Core: 7.0-rc3
CTools: 7.x-1.x-dev
Views: 7.x-3.x-dev
TIA
| Comment | File | Size | Author |
|---|---|---|---|
| test_view.txt | 2.49 KB | Anonymous (not verified) |
Comments
Comment #1
dawehnerRewrite output of html doesn't allow to use style because you can embed js there.
Please use extra css files here.
Additional it doesn't allow in the latest stable version to change the allowed tags, iframe isn't allowed at the moment.
Comment #2
Anonymous (not verified) commentedI understand the "style" issue - one could simply use a class or id there and style it in a css file.
However, the caption/comment on the "Rewrite the output of this field" texatarea reads "The text to display for this field. You may include HTML. ..." It doesn't say "some limited set of HTML" or "HTML that might or might not be rendered." Arbitrarily stripping out HTML with no warning, nor any documentation to suggest what is being done or how to stop it from being done (and providing no way to alter the behavior) is not "works as designed," it's a bug.
Comment #3
dawehnerThere are at least 20 issues in the issue queue which reports this. This is some kind of documentation.
As said the stripping is for security, so it works as designed.
Comment #4
dawehnerOkay.
There are many similar issues, for example: http://drupal.org/node/415896#comment-1408246
This is there fore security reasons.
You can always use theming of the field to provide the exact html you need.
Comment #5
trevorbradley commentedHey deriene. I've just hit this same problem and I'm not so sure I can make the theming work.
I'm attempting to take an image in a view and put an graphic overlay on top of it. I'm attempting to retheme an img tag so that it's an "a" tag, with display:block and the actual image rendered as a background-image to the block, rather than an img tag. Not sure how I can do this without a style tag.
e.g.
I'm not suggesting anything change, stripping out style for security purposes is sound. But there are potential problems with theming that stripping introduces.
I'll post back here if I come up with a clever solution.
EDIT: Never mind me. Don't use a background image... add the overlay as custom content (perhaps using the customfield module) and then use absolute/relative positioning to get everything in place.
(Too stressed out working on this new project to see obvious solutions... sheesh)
Comment #6
alltooeasy commentedDid you ever work this out?
Am trying to rewrite the output of a field so that it appears as the background image of a view (essentially a list of items with some info over the top).
What I'd like to is keep the relative positioning as the image size changes and various other reasons. IS there a means to re-write a view to output a BG image inside another field.
Comment #7
trevorbradley commentedInterestingly enough I was just working on something like this today.
Step one is to just use the image as a displayed field, give it a negative z-index so it sits behind everything else.
The problem here is that position: relative CANNOT be applied to td tags. What I did was created my own .tpl.php file for fields (views-view-fields--my-view-name.tpl.php - copy this from modules/views/theme/views-view-fields.tpl.php) and just wrap everything in a div. Then you can put "position: relative" on that div, and "position: absolute; top:0; left:0; z-index:-1" on your image.
If you're *super* gung ho on using background images rather than tricks with an img tag, placement and perhaps some hidden overflow, you can create copies of the view's template files to your hearts content and go nuts with them.
Good Luck!
Comment #8
alltooeasy commentedEnded up using the z-index value & some absolute positioning inside a relative div. Not the most pretty solution but it works. Also I think if your using views - consider turning off some of the extra CSS output & markup as it can make life a bit harder when it comes to theming.
But equally if you need it, you can work around it. There is also background img module if you're looking to output a specific BG image on a page. I wonder if it couldn't be broadened to cover more - I don't know it well enough to judge, but for everything else, probably look at using z-index