Forum
How do I output using perch_content_create and perch_content_custom together?
<?php
perch_content_create('Plugin Script Customization', array(
'template' => '_plugin-mod-script.html',
'multiple' => false,
));
?>
<?php
perch_content_custom('Plugin Script Customization', array(
'template' => '_plugin-mod-script.html',
));
?>
This mostly works. I delete the region named "Plugin Script Customization," and after I refresh the webpage, I refresh the region list and see that the region has appeared again. And it correctly lists the template file using the automated naming convention from the file name.
The <script> element I'm trying to output to the page doesn't appear in the rendered page source, though. I tried making a copy of the template file without the underscore and changing the corresponding reference in the two page functions, but that had no affect.
When I first just used perch_content and then selected the template from Region Options after choosing a different template initially (because I'm prefixing with an underscore to hide it from my users), it did output to the page. That doesn't seem like a permanent solution, though.
I notice that the "Items" column from the Regions list always says "0" when I try using the combination of perch_content_create and perch_content_custom. That must be the problem; it doesn't automatically populate with one instance of the markup. How do I change that?
Answering my own question.
It's limit => 1 in the perch_content_create array.
Final code:
.....not quite. That worked once, unless I confused something, but I don't think so. Now it's not working again. Code's all still the same. It definitely got output, and then I refreshed the page a few times, and now it's not being output again. Now I try deleting the region again, and when it re-appears after reloading the page the "Items" column shows 0 even though the limit value is still set to 1. But I'm almost certain adding that line the first time is what made it work once.
Debug shows that it is indeed using the template, but there is no other information in the debug output, just the "Using" line.
Does the region have any content?
No. It's just a <script> element with no Perch tags.
If the region has no content, then
perch_content_custom()
will only output thenoresults
section.Why are you using a content region if there's no managed content?
I guess I'm just trying different things while I'm working on a way to put different <script> elements in different pages that come from the same Master Page, in order to load different data through a third-party API that I'm trying to implement for a booking engine. Thanks for the advice.
It sounds like Page Attributes might be better for that job.