I'm a code editor from way back and insist on hand-coding my pages. Plus I'm a php developer and would like to be able to use PHP code in my web-pages. So I want to use the plain text editor in Drupal and I fully expect my code to stay there.

It doesn't.

Example: I have meticulously hand-coded a table putting in zebra stripes, a pain to begin with but I can't figure out how to tell Drupal to do it.

Now a colleague comes behind me and edits the page using the Fck, the "kindof WYSIWYG" editor, and all my hand-coded styles are gone!!

Another example. Having had enough of the above, a colleague more versed in Drupal added some PHP code conditional statements to stripe the tables auto-magically. He saves the page and it works. Great!

Another trip through the "kindof WYSIWYG" editor and all the "quote marks" in the PHP code have been translated into their HTML entity equivalents and the page is completely broken.

OK. I cut the code, paste into Jedit, search and replace, paste it back. And nothing changes. Everything gets changed back to HTML entities. I can't even get it to display correctly once.

How can I tell Drupal to simply leave my hand-written code alone?

Comments

saepl’s picture

disable your WYSIWYG editor for that textarea

whatshisname’s picture

Because my colleagues need to be able to edit that page as well.

That's the reason the university at which I work went to a CMS, i.e., Drupal -- to empower the people in charge of their own content, reducing the dependency on the tech types like me.

AvalancheOfLlamas’s picture

What input format are you using? PHP? Be sure on your input format settings, there aren't any extra filters going on.

whatshisname’s picture

Checked. I'm using the PHP filter.

Though it has flipped back to filtered on me for some unknown reason at least once.

But not this time.

AvalancheOfLlamas’s picture

Ahhh drupal.

Two not-solutions-but-workarounds:

Have you considered a separate text area, such that the body is for PHP use and the text field is for WYSIWYG (turn off CKEditor for the body but not for the field)? With the conditional fields module (http://drupal.org/project/conditional_fields) you could specify an either one or the other if that was required.

A different editor? I use CKEditor, personally, but I've never had the need to combine PHP and rich text in the same page. There are plenty of other ones out there, such as TinyMCE or YUI. Maybe they won't have issues breaking php input formats.

AvalancheOfLlamas’s picture

More specifically, for FCK, edit your global settings under visibility. You can list them by specific boxes, or by path, or both, as well as use exclude or include mode.

whatshisname’s picture

Following up on my own post:

I'll tell you what this looks like to me.

It looks like the ' " ', ' < ' and the ' > ' are being translated into their HTML equivalents upon insertion into MySQL as if all insert statements have the "htmlentities" function being applied to them.

But I wouldn't have a clue how to check to see if that's the case.

AvalancheOfLlamas’s picture

Check out this thread (http://drupal.org/node/525776)

whatshisname’s picture

Thanks for the link.

So the short answer is "No". It can't be done.

Or at least, if you're going to put PHP code *OR* if you're going to hand-code HTML using your own style statements (for which I'm having the same problem) on a Drupal page, you have to cut off the WYSIWYG editor for that page so that no one who is HTML/Php adverse, which is everyone else in the department, can edit the page.

So ... <sarcasm>great!</sarcasm>

At least I know to give up now. :-(

AvalancheOfLlamas’s picture

I also realized after I said this:

Have you considered a separate text area, such that the body is for PHP use and the text field is for WYSIWYG (turn off CKEditor for the body but not for the field)? With the conditional fields module (http://drupal.org/project/conditional_fields) you could specify an either one or the other if that was required.

That you could combine this with Computed Field (http://drupal.org/project/computed_field) to make a pseudo body field that contained both php and content in one field. It would require the php to be before or after though, which it seems like would be a problem for what you need. Just offering the suggestion though if others stumble here.

bsenftner’s picture

I have a few sites where I use CKEditor as my usual content-body editing tool, and on several of those site's pages I need to mix hand coded html and php in a similar manner as one would see a Drupal page template.

The key is to make sure that CKEditor does not get a chance to modify my hand-coded content via the global settings for CKEditor at admin/settings/ckeditor/editg, where I enter the "component-URL" to any pages where I have hand-coded content-bodies into the "Fields to exclude/include" with that set to 'exclude'. This prevents the CKEditor from launching automatically on those pages.

You can also turn the CKEditor off on any page which it is running via the node-edit page's "Switch to plain text editor" link; this will 'abort' the CKEditor without running it through the htmlentities() function.

In general, if you want to prevent the CKEditor from modifying your content when you submit, make sure you're in "plain text editor" mode when you click the node's submit button.

roper.’s picture

I have meticulously hand-coded a table putting in zebra stripes, a pain to begin with but I can't figure out how to tell Drupal to do it.

theme_table()?

whatshisname’s picture

I looked at that theme but from what I can tell by looking at the source code, it only works on information drawn from an SQL query. It doesn't look like it would work on a statically coded table.

But correct me if I'm wrong, please.

joachim’s picture

Theming and database are completely separate. theme_table() will take whatever data you give it.

saepl’s picture

I agree with alan.pinkert in that you need to somehow separate the php that only you have access to edit it and provide the other users with the ability to use the WYSIWYG. How to do that is a bit of an interesting question there are many options and which one you choose has a lot to do with what outcome you want to achieve.

A question that is coming to my mind is why do you need to have PHP on a page? What is the PHP doing? And then, can it be done with a module or in the theming layer instead of in the node?

whatshisname’s picture

Understand that I'm new to Drupal and have been a PHP developer for over a dozen years. So working in Drupal feels like being in a straight-jacket. We've been mandated to use Drupal so here I am.

So I started the PHP solution to the table striping problem because, as mentioned previously, I had hand-coded a static table created by my department chair. It was busy looking so she asked me to make it more readable, thus the attempt to zebra-stripe it. Later she comes behind me with the Fck editor, adds a row and Fck wipes out the striping. There goes 45 minutes of my life I'll never get back.

Ok, so I say to myself, why don't you just apply some PHP code to it. Maybe the PHP code will persist after a stroll through Fck. I hadn't had the chance to apply PHP code to a Drupal page yet so I figured this would be the time to try.

Next I discover that my time-tested function for doing such things doesn't work in Drupal because evidently you can't put functions on a Drupal page. So my friend and colleague supplied me with some PHP code, not dependent on a function, and he got the tables to stripe. That is, until the page took another stroll through Fck.

I looked for a striping module but couldn't find one. And the one theme I looked at doesn't appear to apply to static HTML code.

But what do I know? :-)

AvalancheOfLlamas’s picture

Some themes have a tr.row-even and tr.row-odd, for CSS striping, built in. Have you tried that?

Alan

whatshisname’s picture

though I have looked at some theme code.

1) I'm stuck with the theme the University sets up for us.

2) Having said that, would a theme apply to a statically coded table?

On my non-Drupal sites, I have some javascript that automagically stripes tables and I've been quite pleased with it. It requires adding an "onload" directive that passes several parameters so I presume I can't make that work in Drupal. :-(

AvalancheOfLlamas’s picture

Theoretically, it's all being built-in to CSS. See http://www.w3.org/Style/Examples/007/evenodd. Note: that warning at the top is quite old now. Col support is full across the board (http://reference.sitepoint.com/html/col) and dynamic nth-child is getting there (FF 3.5+, Safari 4+, Chrome 4+, IE not supported until 9+)

But of course, it's better to include as much support as possible. For a statically coded table, yes, each tr would need its own class="even" or "odd". I believe that's how Drupal currently does it with any tables it has built in. Still, if you coded all your tables that way, you could theme them all at once, easily.

You can add style in the header (see http://drupal.org/node/189985) or in your own css pages. Are you sure you can't add anything to the theme for just your site/partition?

Alan

joachim’s picture

This sounds crazy.

If your table is from stored data, create a custom module to output that page. Or use Views.

Alternatively, segregate the parts you need to edit and your colleague needs to edit. But really, there's no need to be hand-coding a table.

Anonymous’s picture

There might be a module that does this.

For example:

Computed field
Data

Anonymous’s picture

Sheetnode looks interesting for this.

Take a look at this as well: http://drupal.org/node/175095

You could possibly make it a CCK field and then add a token, see:
http://drupal.org/node/888318#comment-3352250

It might do the trick (with some extra code writing). It would allow users to add tables within their own content.

Edit:

I'm not suggesting you give users access to PHP code, which could be a bad idea, but maybe you can find a way with permissions, or setting up a token that people could include having the php code elsewhere.

Edit 2:

Take a look at the Matrix Field and the TableField modules as well. These modules work with tables.

bethhauck’s picture

For anyone still having this problem, the Table Alternate Rows module applies even and odd classes to table rows inside editable content areas, via a filter: http://drupal.org/project/table_altrow. It worked perfectly for me.

There's also this solution if you're trying to add vertical zebra striping, although I haven't tested it myself: http://snipplr.com/view/3607/drupal--theme-table-with-columstriping/