Jump to content

Recommended Posts

Posted

Hi there,

I've got an old site with tons of content written in markdown. Wysiwyg editing has matured a bit since 2010 and the client would like to change to ckedit. The question is what to do with all the old markdown, can it be converted somehow?

Did anyone do this? Any tips?  – thanks!

Posted

Hi @joe_g

Maybe you can loop over all your page and just save output of your markdown field to the newly created ckeditor field

$yourpages = $pages->find("template=some");

foreach($yourpages as $p) {
	$p->ckeditorfiedl = $p->oldfield
	$p->save();
}

 

  • Like 3
Posted

@Zeka's suggestion is the right direction, but a couple of extra things are needed:

$your_pages = $pages->find("template=some_template");

foreach($your_pages as $p) {

    // Output formatting must be off before manipulating and saving the page
    $p->of(false);
    
    // You need to get the formatted value of the markdown field
    // i.e. with the textformatter applied
    $p->ckeditor_field = $p->getFormatted('markdown_field'); 
    
    $p->save();

}

Or a shorter way that takes care of the output formatting using setAndSave():

$your_pages = $pages->find("template=some_template");

foreach($your_pages as $p) {

    // Normally you wouldn't want to save a formatted value with setAndSave()
    // but in this case we do
    $p->setAndSave('ckeditor_field', $p->markdown_field);

}

 

  • Like 2

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...