Forum

Thread tagged as: Question, Problem

Blog post title not showing in block

I'm using perch blocks within the post template of the blog. I'm trying to call in the postTitle

For example:

<h5><perch:blog id="postTitle" type="text"/></h5>

However the template shows nothing.

This works fine outside of the repeater:

<h1><perch:blog id="postTitle" type="text"  /></h1>

Is there a limitation preventing the postTitle from being included in a repeater within a block?

Tony Astley

Tony Astley 0 points

  • 2 years ago
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Tony,

The documentation discusses accessing content from outside the repeater: https://docs.grabaperch.com/templates/repeaters/

I'd tried that technique and it didn't work

title="<perch:blog id="parent.postTitle"/>"

For the record I have this working perfectly fine within a standard page, it's only within the blog templates it doesn't work.

Fixed it - passing a variable into the template and not using the parent. syntax works.

<?php 

    $blogTitle = perch_blog_custom(array( 
                'filter'=>'postSlug', 
                'match'=>'eq', 
                'value'=>$slug, 
                'template'=>'post_title.html',  
            ), true);

    PerchSystem::set_var('blog-title', $blogTitle);

    perch_blog_custom(array( 
        'filter'=>'postSlug', 
        'match'=>'eq', 
        'value'=>$slug, 
        'template'=>'post.html',  
    ));
?>

Then to get the blog-title in the repeater in the repeater.

title="<perch:blog id="blog-title"/>"

Seems like I'm missing something obvious here but that's a lot of code to access a page title?

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

I'd tried that technique and it didn't work

I think it's because you have 2 levels here so you have to add scope-parent to both perch:blocks and perch:repeater:

<perch:blocks scope-parent>
    <perch:block type="text" label="Text">
        <perch:repeater id="test" label="Text" scope-parent>
            <perch:blog id="parent.parent.postTitle" type="hidden">
            <perch:blog id="text" label="Text" type="text">
        </perch:repeater>
    </perch:block>
</perch:blocks>

p.s. try avoiding hyphens in your IDs:

Use letters, numbers and underscores only for an id.

https://docs.grabaperch.com/templates/attributes/id/

Thank you so much for posting the content here at the platform. I would also like to share important info on visit: https://www.downloadaoldesktopgoldshield.com/