Jump to content

Extended field context


Recommended Posts

I think most of us know that the wysiwig editors can be a pain if you want to input more than just some paragraphs...

e.g. if you have to work with nested divs in the body of a page. So for some pages, the editor is best left switched off.

Only solution i can think of at the moment is to create a new template, a new field for body content without editor, and assign the template to the page. Works, but is cumbersome.

It would be extremely helpful if we could switch the editor on and off via field context settings. What do you think? Is this even possible?

Link to comment
Share on other sites

My solution would be:

1. create a new field called "use_wysiwyg" and choose "checkbox" as type

2. create a field "body_raw" or whatever you want to call the body field without wysiwyg

3. Add both fields to your template and save it

Now let the processwire magic play:

4. Now click on "body" 

post-140-0-74564000-1401369543_thumb.png

And go to Visibility -> Show this field only if... and add the following:

post-140-0-33740100-1401369538_thumb.png

5. Do the same thing with "body_raw". Only difference: "use_wysiwyg=0"

Now the wysiwyg editor should only appear if the checkbox is checked.

In your template do this to get the content: $page->get('body|body_raw');

  • Like 6
Link to comment
Share on other sites

@nico - good solution, only issue is what if the editor enters some stuff in the wysiwyg, and then later decides to switch to raw; the pipe wouldn't work right, so maybe instead use the checkbox to determine which to show on output?

echo $page->use_wysiwyg==0 ? $page->body_raw : $page->body;
Edited by Macrura
  • Like 3
Link to comment
Share on other sites

@nico - good solution, only issue is what if the editor enters some stuff in the wysiwyg, and then later decides to switch to raw; the pipe wouldn't work right, so maybe instead use the checkbox to determine which to show on output?

echo $page->use_wysiwyg=0 ? $page->body_raw : $page->body;

Missing an =? ($page->use_wysiwyg==0) :-)

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...