Forum

Thread tagged as: Problem

Markdown fields broken in Perch 2.8.18 when using perch_template()

I have just updated a site to Perch to 2.8.18 and am seeing raw (and broken) HTML tags being displayed in Markdown-based regions.

The problem only seems to be occurring when using perch_template() to display content. Content displayed with perch_content() renders correctly, and perch_content_custom() is retrieving the data correctly.

(Possibly similar to this problem - https://forum.grabaperch.com/forum/11-21-2015-markdown-not-working-after-2816-update)

Can you help, please?

Template code:

<perch:content id="body" type="textarea" label="Body" markdown="true" editor="markitup" required="true" size="l" />

Section of data retrieved using perch_content_custom():

[body] => <p>Lorem ipsum dolor sit amet, <a href="https://test.com" title="">consectetuer adipiscing</a> elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>

Output from perch_template() (using same template as the one used to capture the data). Notice how the data is wrapped in a <p> tag, and the <a> is completely broken:

<p>&lt;p&gt;Lorem ipsum dolor sit amet, &lt;a href=”<a href="https://test.com">https://test.com</a>” title=”“&gt;consectetuer adipiscing&lt;/a&gt; elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.&lt;/p&gt;</p>

Diagnostics:

    Perch: 2.8.18, PHP: 5.4.22, MySQL: mysqlnd 5.0.10 - 20111026 - $Id: e707c415db32080b3752b232487a435ee0372157 $, with PDO
    Server OS: WINNT, apache2handler
    Installed apps: content (2.8.18), assets (2.8.18), categories (2.8.18), perch_forms (1.8.3)
    App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_forms' );
    PERCH_LOGINPATH: /perch
    PERCH_PATH: C:\xampp\htdocs\terencedonovan\perch
    PERCH_CORE: C:\xampp\htdocs\terencedonovan\perch\core
    PERCH_RESFILEPATH: C:\xampp\htdocs\terencedonovan\perch\resources
    Image manipulation: GD
    PHP limits: Max upload 100M, Max POST 100M, Memory: 256M, Total max file upload: 100M
    Resource folder writeable: Yes
    HTTP_HOST: terencedonovan
    DOCUMENT_ROOT: C:/xampp/htdocs/terencedonovan
    REQUEST_URI: /perch/core/settings/diagnostics/
    SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Jonathan Brain

Jonathan Brain 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you passing already encoded HTML back through the template? If so, you need to add encode="false" else it will be encoded twice.

Hi Drew,

I've added encode="false" into the template tag (as below), but it doesn't fix the problem.

<perch:content id="body" type="textarea" label="Body" markdown="true" editor="markitup" encode="false" required="true" size="l" />

The content was being displayed correctly until I upgraded from 2.8.13 to 2.8.18.

Any other ideas?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me the code you're using? All our unit tests are passing, so there's obviously some subtly to it.

OK, here goes...

This is the main PHP doc. The content for this page is stored in a "multiple" region, and only one of the region items is displayed at once. Rewrite rules determine which one, using the slug held in $_GET['arg'].

If the slug is valid, the corresponding content is then passed to perch_template() to be output.

<?php include($_SERVER['DOCUMENT_ROOT'].'/lib/preload.php'); ?>
<?php
    // get perch structures for About section
    $dummy = perch_content('About', true);
    $pages = perch_content_custom('About', array('skip-template' => 'true'), true);
    $page = false;
    $page_nav_items = array();


    if ( count($pages) > 0 ) {

        if ( isset($_GET['arg']) && $_GET['arg'] != '' ) {

            // If the page exists, load it
            // Otherwise, redirect to 404 page
            foreach ( $pages as $p ) {
                if ( $p['slug'] == $_GET['arg'] ) {
                    $page = $p;
                }
            }

            if ( !$page ) {
                // Page not found
                throw_404();
            }
        }
        else {
            // No arguments - show first page
            $page = $pages[0];
            header('Location: /about/' . $page['slug']); 
        }


        // Create nav
        $page_nav = '';
        foreach ( $pages as $p ) {
            $active = '';
            if ( $p['slug'] == $page['slug'] ) { 
                $active = ' active';
            }
            $page_nav .= '<li class="nav-main-item' . $active . '"><a class="nav-main-link" href="/about/' . $p['slug'] . '">' . $p['heading'] . '</a></li>';
        }

    }

?>

<?php perch_layout('global.header', array('page_title' => $page['heading'], 'meta_description' => $page['meta_description'])); ?>

    <div id="mainContent">

        <nav id="subMenuPanel">
            <ul class="nav-sub"><?php echo $page_nav; ?></ul>
        </nav>

        <div id="bodyText_max-width">
            <?php perch_template('content/article.html', $page); ?>
        </div>

    </div>

<?php perch_layout('global.footer'); ?>

The content is entered using 'content/article.html' - the same template as perch_template() is using to output it. Here's the template (including the encode tag):

<h1><perch:content id="heading" type="text" label="Heading" required="true" title="true" /></h1>
<perch:if exists="intro"><p class="intro"><perch:content id="intro" type="textarea" label="Introduction" size="s" /></p></perch:if>

<perch:if exists="image"><img class="imageInsert" src="<perch:content type="image" id="image" label="Image" width="260" crop="true" quality="100" sharpen="0" />" alt="<perch:if exists="alt"><perch:content type="text" id="alt" label="Image alt" /><perch:else /><perch:content id="heading" type="text" label="Heading" /></perch:if>"/></perch:if>

<perch:content id="body" type="textarea" label="Body" markdown="true" editor="markitup" encode="false" required="true" size="l" />

<perch:content id="slug" type="slug" for="heading" suppress="true" />
<perch:content id="meta_description" type="textarea" label="Meta description" size="xs" divider-before="Meta" suppress="true" />

Thanks!

Hi Drew,

Have you been able to get to the bottom of this problem?

Thanks, Jon

Drew McLellan

Drew McLellan 2638 points
Perch Support

Not yet - it's still on my list.

Here's some further information that might be handy:

This is the content captured by the perch_content_custom() call. It's exactly as I'd expect:

Array
(
    [0] => Array
        (
            [_id] => 7
            [heading] => Terence Donovan
            [_title] => Terence Donovan
            [intro] => Terence Donovan was born, the only child of a working class family, in East London in 1936. Fascinated by photographs and photographic processing as a young boy, his professional photographic life started at the age of 11 at the London School of Photo-Engraving, which he left at 15 to become a photographer’s assistant. After a year at the John French studio (1957–58) he left, opening his own first photographic studio in 1959 at the age of 22.
            [image] => /perch/resources/terencedonovanimage.jpg
            [alt] => Terence Donovan
            [body] => <p>The studio was an instant success. Work poured in and his versatility attracted a range of clients, including the leading advertising agencies and the fashion and lifestyle magazines of the time, among them Vogue, Queen and Man About Town and later the influential Nova, Marie Claire and Elle. He accomplished much at an early age and came to particular prominence in the 1960s as part of the now famous era of ‘Swinging London’. Associated at this time with David Bailey and Brian Duffy, these three English photographers revolutionised the world of magazine and newspaper photography.</p>
            [slug] => terence-donovan
            [meta_description] => 
            [_page] => /about.php
            [_pageID] => 3
            [_sortvalue] => 1000
        )

    [1] => Array
        (
            [_id] => 8
            [heading] => The archive
            [_title] => The archive
            [intro] => 
            [image] => 
            [alt] => 
            [body] => <p>Lorem ipsum dolor sit amet, <a href="https://test.com" title="">consectetuer adipiscing</a> elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
            [slug] => the-archive
            [meta_description] => 
            [_page] => /about.php
            [_pageID] => 3
            [_sortvalue] => 1001
        )

    [2] => Array
        (
            [_id] => 9
            [heading] => Copyright terms
            [_title] => Copyright terms
            [intro] => 
            [image] => 
            [alt] => 
            [body] => <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
            [slug] => copyright-terms
            [meta_description] => 
            [_page] => /about.php
            [_pageID] => 3
            [_sortvalue] => 1002
        )

)

And here's an example of the content that is being passed to the perch_template() call (in the $page variable):

Array
(
    [_id] => 8
    [heading] => The archive
    [_title] => The archive
    [intro] => 
    [image] => 
    [alt] => 
    [body] => <p>Lorem ipsum dolor sit amet, <a href="https://test.com" title="">consectetuer adipiscing</a> elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
    [slug] => the-archive
    [meta_description] => 
    [_page] => /about.php
    [_pageID] => 3
    [_sortvalue] => 1001
)

Thanks in advance for your help.

I'm experiencing the same issue.

I'm pulling in some collection items

$contestants =  perch_collection('Gladiators', array(
                    'skip-template' => true,
                    'sort' => 'score',
                    'sort-order' => 'ASC',
                    'count' => 5
                ));

Shuffling the array and and taking the top two...

//Randomise them
shuffle($contestants);

//Pit the top two against each otehr
$con1 = $contestants[0];
$con1['index'] = 1;
$con2 = $contestants[1];
$con2['index'] = 2;

and then using perch_template() to output the html...

<?php perch_template('content/collections/gladiator.html', $con1); ?>

and

<?php perch_template('content/collections/gladiator.html', $con2); ?>

This results in <p> tags being output around the markdown fields.

I'm using 2.8.20.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Caleb

please raise a new thread for your own issue including your Diagnostic Report and template - thanks!

Apologies. I'll raise it again in a few days with the proper info.