We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Problem

perch_template - stripping html tags

I am using a list/detail page on a website, so the 'detail' is provided by perch_content_custom. As I don't want to echo the result straight away (I want to store it in a variable), I am using the "skip-template" option.

I then pass the variable to perch_template, to run against a template (again, I don't want this to echo immediately, so it's passed to a variable).

One of the fields contains text styled by textile, so when the data is passed through perch_template, it is formatted with html tags. In this instance, I don't want the html tags, so in my template I have added the "striptags" option. However, the resulting output still has the html. Is this expected behaviour? Or should perch_template be honouring those attributes?

Setting the "raw" option on perch_content_custom obviously removes html tags, but I end up with underscores etc in the text from textile.

Cheers, Dunc

Duncan Revell

Duncan Revell 78 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

So you're basically saying that the striptags attribute isn't working for you?

Can you show us your template tag?

Duncan Revell

Duncan Revell 78 points
Registered Developer

I suppose that's the gist of it....

Some of the processes I'm using are a bit convoluted - I've integrated Perch into an existing CodeIgniter website. Here is how the region is created:

        perch_content_create($data['region'], array(
            'page' => $data['url'],
            'template' => 'news_item.html',
            'multiple' => true,
            'edit-mode' => 'listdetail',
            'sort' => 'date',
            'sort-order' => 'DESC',
            'columns' => 'title,date',
            'add-to-top' => true
        ));

The news_item template is as follows:

<perch:content id="title" type="text" label="Article title" required="true" title="true" />
<perch:content id="slug" for="title" type="slug" />
<perch:content id="date" type="date" label="Article date" format="j M Y" required="true" />
<perch:content id="intro" type="textarea" label="Intro" textile="true" size="s" required="true" />
<perch:content id="article" type="textarea" label="Article" textile="true" editor="markitup" size="xxl autowidth" required="true" />
<perch:content id="user" type="user" label="Author" />

This sets up the backend for entering the region items.

Later on, I need to re-use some of this data for some html meta tags:

        PerchSystem::set_var('news_url', 'http://website/news/'. $season .'/');
        $news_meta = perch_content_custom('News 20' . implode('/',str_split($season,2)), array(
            'page' => '/news/'. $season,
            'skip-template' => true,
            'filter' => 'slug',
            'match' => 'eq',
            'value' => $slug,
            'count' => 1
        ));
        $this->head['misc'] = perch_template('content/_news_item_meta.html', $news_meta, true);

The template I am then using is as follows:

<meta property="og:title" content="<perch:content id="title" type="text" label="Article title" />" />
<meta property="og:url" content="<perch:content id="news_url" /><perch:content id="slug" for="title" type="slug" />" />
<meta property="og:description" content="<perch:content id="intro" type="textarea" label="Intro" striptags="true" />" />
<meta property="og:type" content="article" />
<meta property="article:published_time" content="<perch:content id="date" type="date" label="Article date" />" />
<meta property="og:image" content="http://website/images/badge_square.jpg" />

This is the browser output:

<meta property="og:description" content="&lt;p&gt;Neither side troubled the score sheets this weekend, leaving the Reserves in a spot of bother.&lt;/p&gt;" />

Anything else you need, let me know.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you try adding html="true" to the same tag? It may be that it's being escaped first, so the tags aren't there to strip.

Duncan Revell

Duncan Revell 78 points
Registered Developer

That's done it Drew.

Having read that again, I think I've seen you recommend that to others on the forum, but the docs push you away from it as soon as you use textile or markdown...?

Thanks for the help, Dunc