Forum

Thread tagged as: Problem

Using template includes with blocks

I’m trying to use an include within a perch block, but the included template is not showing up. Is there something obviously wrong with my template?

<perch:blocks>
    <perch:block type="text" label="Testimonial">
        <perch:template path="testimonial.html" />
    </perch:block>
    <perch:block type="text" label="Text">
        <perch:content id="text" type="textarea" markdown="true" editor="markitup" size="l" label="Text" />
    </perch:block>
</perch:blocks>

It shows the Text block available to add but not the testimonial one.

Here is my diagnostic report:

SUMMARY INFORMATION

Perch: 2.8.13, PHP: 5.5.17, MySQL: 5.5.38, with PDO
Server OS: Darwin, cgi-fcgi
Installed apps: content (2.8.13), assets (2.8.13), categories (2.8.13), perch_blog (4.6)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_blog', );
PERCH_LOGINPATH: /perch
PERCH_PATH: /Users/TwoLittleFishes/Dropbox/sites/helenaclayton.co.uk/perch
PERCH_CORE: /Users/TwoLittleFishes/Dropbox/sites/helenaclayton.co.uk/perch/core
PERCH_RESFILEPATH: /Users/TwoLittleFishes/Dropbox/sites/helenaclayton.co.uk/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
Resource folder writeable: Yes
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
REQUEST_URI: /perch/core/settings/diagnostics/
DOCUMENT_ROOT: /Users/TwoLittleFishes/Dropbox/sites/helenaclayton.co.uk
HTTP_HOST: helenaclayton.local
Nick Bramwell

Nick Bramwell 5 points

  • 6 years ago

Hi Nick

Is testimonial.html template in the content folder or is it in a sub-folder within the content folder?

If it is you may need to add that to the path...

      <perch:template path="sub-folder-name/testimonial.html" />

Yes the testimonial.html file is in the main templates/content folder.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Try

<perch:template path="content/testimonial.html" />

Thanks Drew,

it seems to work with or without the /content as the debug in both shows:

Using sub-template: /templates/content/testimonial.html

It looks like the problem might be with the testimonial.html template, which works fine alone but may be doing something odd in a block, here is the complete code (instead of using the include) which still only shows the option to add Text:

<perch:blocks>

    <perch:block type="text" label="Testimonial">
        <blockquote>
            <perch:content id="testimonial" type="textarea" label="Testimonial" markdown="true" editor="markitup" />
            <perch:if exists="source"><cite><perch:content id="source" type="text" label="Source" /></cite></perch:if>
        </blockquote>
    </perch:block>

    <perch:block type="text" label="Text">
        <perch:content id="text" type="textarea" markdown="true" editor="markitup" size="l" label="Text" />
    </perch:block>

</perch:blocks>

Just discovered changing it to:

<perch:blocks>
    <perch:block type="textarea" label="Testimonial">
        <perch:template path="testimonial.html" />
    </perch:block>
    <perch:block type="text" label="Text">
        <perch:content id="text" type="textarea" markdown="true" editor="markitup" size="l" label="Text" />
    </perch:block>
</perch:blocks>

works, the difference is that the testimonial block now has a type of textarea, instead of text. The second block though works with a type of text even though the content has a type of textarea.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can't have two blocks of the same type. You'd be better to use type="testimonial" for your Testimonial block - it's more descriptive of what you're actually doing.

Thanks Drew, I hadn’t realised that the perch:block type acted as an ID, I thought it worked like the perch:content type.