custom content using blocks
I'm trying to load using custom_content from a page that has a single region with blocks, template is below:
<!--* Main heading and introduction and graphic *-->
<perch:before>
<perch:template path="content/blocks/introduction_block.html" />
</perch:before>
<perch:blocks divider-before="Choose content block to suit you're content as many or little as you want, you can even reorder them.">
<!--* Brand logos *-->
<perch:block type="brand-logos" label="Brand logos">
<perch:template path="content/blocks/brand_logos_block.html" />
</perch:block>
<!--* Text *-->
<perch:block type="title-text" label="Heading and Text">
<perch:template path="content/blocks/text_block.html" />
</perch:block>
<!--* Lists used for things like Features or Benefits *-->
<perch:block type="text" label="Information List">
<perch:template path="content/blocks/list_block.html" />
</perch:block>
</perch:blocks>
Perch will load all the data from the 'Product Details' region:
perch_content_custom('Product Details', array(
'page' => '/products-and-services/*',
));
I only want to load the 'Brand logos' data, if I use the below it doesn't load any data:
perch_content_custom('Product Details', array(
'page' => '/products-and-services/*',
'template' => 'blocks/brand_logos_block.html',
));
This is the brand logos template:
<ul class="brand-logos">
<perch:repeater id="brand-logos" label="Add a brand logo">
<li><img src="<perch:content id="brand-logo" type="image" width="125" label="Image" bucket="brands" />" alt="<perch:content type="text" id="alt" label="Description" required="true" help="Brand name" />" srcset="<perch:content id="brand-logo" type="image" width="125" label="Image" density="2" bucket="brands" /> 2x, <perch:content id="brand-logo" type="image" width="125" label="Image" density="3" bucket="brands" /> 3x"></li>
</perch:repeater>
</ul>
How do I get only that block of data to display?
Your brand logos template needs to include the
perch:blocks
tags andperch:block
tag from the master.Ok I've done that and it loads the data :o) BUT it repeats it twice?
Sorry, meaning it outputs the set of data twice on the page.
Can you show me the code you're using?
hmm now I've added the perch:blocks tags and perch:block tag to the brand logos template the perch edit form has lost the ability to add any logos! I think I'm not understanding blocks which is a shame. I guess I'll have to go back to just regions :o(
The code I was using is above.
Ok, I didn't notice you were including one template inside the other.
Clearly now you're importing a set of blocks tags inside an existing set, which isn't going to work. You'll need to split the templates down.
OK started with fresh eyes this morning…I'm still confused, can you clarify for me. I'm following the tutorial for Template includes and Blocks: https://docs.grabaperch.com/video/v/template-includes-and-blocks/
This all works correctly using the code at the start of this thread, I can add multiple blocks and content and reorder them. The only difference between mine and the video is that two of the templates uses repeaters. The content all displays correctly on the webpage, all good so far.
If I then try and use the custom_content tag to load just the list of brand logos on another page it finds the template but doesn't load the content?
So this loads all the content to a different page from the product page including brand logos and other content in blocks:
I only want to load one of the blocks of content the 'brand logos':
As soon as I use the above no content loads, but if I use the below it will load the introduction text which as above is outside the blocks tag:
So to sum up… everything is working as per video and as I envisaged except I can't use perch_custom_content to load content from within blocks. I can send you the files if you want?
My diagnostics are… (local MAMP setup)
SUMMARY INFORMATION
Ok, if your templates are back to how they were at the start, I think you need to create a template with this:
Then use this new template with your
perch_content_custom()
call. A block always needs to appear within<perch:blocks>
tags whenever it's used.Fantastic thanks! that works a treat… So effectively if you want to use blocks with custom_content then you have to do it with the perch:blocks inside the template that's included and NOT like the video?
The below now works:
BUT there is a problem… I've separated the code into includes so I can reuse elsewhere, so for example the below is used on other pages:
So if I add the required code to this template:
When this template is used elsewhere it doesn't show as a normal region but a block.
So essentially to use custom content with blocks and includes to reuse code, I would have to create two templates:
text_template.html
text_block_template.html
Is that correct?
That's right - is it not working?
Fantastic thanks! that works a treat… thanks for your help :o)
Ok maybe not! I've just gone to add some more content and now the Blocks appear and you can click them to add new content but it just displays the grey bar and no fields?
This is what I'm using:
Product details region template:
Included template:
One set of
<perch:blocks>
tags should wrap your blocks.So if you have one block:
If you have multiple blocks:
It's no more complex than that. That's all there is to it.
Ok remind me not to use Blocks and Custom Content again! :o(
This is now working by adding another template just for the using with custom_content and blocks…
Blocks added around ALL includes as there is multiple includes:
Individual Blocks template WITHOUT blocks tag pair as this is included in a file that has the blocks tag pair:
This now displays as desired in the admin interface. Now for the custom_content bit:
To load only one of the blocks of content on another page:
perch_custom_content now loads the data :o) Phew! have I made this complicated or is it just that's the only way to do it ?
Thanks again.
You seem to be making heavy weather of it, but I don't know what you're trying to achieve and if Blocks are the best tool for that or not.
Hi Mark and Drew,
i have a very similar problem, but for me Marks solution didn't work (my english is not so well, i know...).
If i include the content from a page with the original blocks-template, all blocks we displayed correctly. Fine. But i want to have only the content of ONE these blocks (like Mark).
So i include the content from a page with an other blocks-template that only contains the block that i want. Now i have only the content from this block - great - but: twice :-(
I have all tried out - Marks solution and some things more. Nothing. Or twice.
The code:
Original-blocks-template.html :
The used-template.html used in perch_content_custom:
PHP:
All fine but twice!
Thank for some ideas and help! Thomas
Thomas. After it working on my local copy and display just once. I have just moved it over to the live server and it loads the blocked content twice as well?!
Any ideas drew?
Hi Mark, i found a solution for me. Not really cool but it works.. I think, there is a little bug inside the "blocks". I changed all, that i found. But: Every time it displays the content twice.
OK. I set my original blocks region as a multiple region and use the blocks that i didn't want to reuse on another page in another item of that multiple region.
That works.
Fore your: You have to set your blocks region as multiple and "outsource" your brand logos to another item. I hope, it's not so much effort.
Best regards, Thomas