Posts by Stephen Meehan

    To use _block_id inside a perch:repeater, just do this:

    Add scope-parent to the perch:repeater, then add id="parent._block_id" to the ID inside the perch:repeater

    1. <perch:repeater scope-parent id="your_repeater_id"><perch:content id="parent._block_id" type="hidden">-item-<perch:content id="perch_item_index" type="hidden"></perch:repeater>

    When combined with perch_item_index, this will output a unique value per item inside a repeater. A useful addition if you intend to have more than one block on a page.

    More info in the docs, at the bottom of the page, 'Accessing content outside the repeater'.

    I've hit a bump with this...

    When I have more than one block on a page, the value of perch_item_index is no longer unique.

    Using perch:showall I can see each block as a unique ID

    <perch:content id="_block_id">

    I was hoping to combine _block_id and perch_item_index to make a unique value within a repeater

    Unfortunately, I can't access _block_id inside a repeater

    I've created variables from IDs in the past, but the way I do that involved referencing a fixed page. As this is a block, it could appear anywhere.

    Is it possible to make _block_id a variable, so I could use it inside a repeater

    Or perhaps there's a better way to create a unique value per item in a repeater ?


    I'm using a repeater in my template.

    I'd like to be able to output a unique CSS class for each item in a repeater, something like this:

    1. <div class="item-0">...</div>
    2. <div class="item-1">...</div>
    3. <div class="item-2">...</div>

    I've used <perch:showall> and I can see each repeater item starts with a unique array, simplified example below.

    Is it possible to use these array numbers in my HTML template? If not, perhaps I could use the [assetID]?

    Health check

    • Perch Runway is up to date
    • PHP 7.1.26 is up to date
    • MySQL 5.7.25 is up to date
    • Image processing available

    Figured it out.

    Found this post

    I was looking at the debug on the page, not in the control panel (!).

    I had this error in Perch control panel:

    1. { "error": { "errors": [ { "domain": "usageLimits", "reason": "ipRefererBlocked", "message": "The request did not specify any referer. Please ensure that the client is sending referer or use the API Console to remove the referer restrictions.", "extendedHelp": "" } ], "code": 403, "message": "The request did not specify any referer. Please ensure that the client is sending referer or use the API Console to remove the referer restrictions." } }

    Within Google API settings 'Application restrictions', I had restricted the API key to a specific domain - I must have set it up wrong. When I (temporarily) remove it and press save, the YouTube Fieldtype works a charm.

    I'll leave it there for now. At least I know the issue is related to 'Application restrictions' in Google API settings ad has nothing to do with the YouTube Fieldtype.

    Thanks for the support!


    YouTube embeds are working using the YouTube Fieldtype

    I've setup my YouTube API key, and checked Debug (no errors).

    1. <!--* output="embed" - Displays video on page *-->
    2. <perch:content width="560" height="315" id="video" type="youtube" label="YouTube URL" output="embed">

    However, I've been unable to get any other output types to work?

    1. <!--* None of these are working? *-->
    2. <perch:content id="video" type="youtube" output="title" />
    3. <perch:content id="video" type="youtube" output="description" />
    4. <perch:content id="video" type="youtube" output="date" />

    Screenshot below shows <perch:showall>


    The three URLs in the screenshot above show the output of output="title", output="description" and output="date"

    Is there anything else can try?

    Perch information

    Came up with a solution...

    I created a couple of variables, one to check the current category. And another so I could use id="cd_form", from a category template in my blog template.

    I'll post it here next week.

    Thanks for the replies ryan, have a great weekend.


    At the moment I've hardcoded the control-and-display category, this will be a variable

    I would have thought  'category' => 'news/control-and-display/' would have done the trick - but it looks like it's being ignored as perch_blog_custom  is still displaying id="cd_form" from other categories?

    The original code works, in the sense that it displays id="cd_form". The problem is when a post is associated with more than one category. When that happens id="cd_form" is output more than once. Does that make sense?:/


    I've used perch_item_first in the past, but in this instance I need the ID to be pulled from a specific category.

    A bit of background: I've added a third-party form to my website, each category has a different form. The form is identified by a unique ID, unfortunately I can't use perch_item_first, as that would only display the ID from the first category a post is linked to.


    I'm using id="cd_form" from a category template in a blog post - this bit works...

    The problem is when a blog post is associated with more than one category, id="cd_form" is displayed twice (or however many categories the post is linked to).

    How do I limit the output to just one category?

    I've hardcoded a few values below, to make the code easier to read

    1. perch_blog_custom([
    2. 'blog' => 'news',
    3. 'category' => 'news/control-and-display/', //Limit to one category
    4. 'filter' => 'postSlug',
    5. 'match' => 'eq',
    6. 'value' => perch_get('s'),
    7. 'template'=> my-template.html'
    8. ]);

    my-template.html looks like this:

    1. <perch:categories id="categories" set="news">
    2. <perch:category id="cd_form" type="text" />
    3. </perch:categories>

    I guess the problem is related to the way I'm filtering the post. I'm using 'filter' => 'postSlug' and the slug isn't unique (when a post is associated with more than one category)

    I thought using the category option in perch_blog_custom would fix this?

    I then thought perhaps a double filter might work:

    But that doesn't work, adding the second filter breaks perch_blog_custom, nothing shows...

    What's the best way to achieve this?


    Hi hus_hmd

    Ah, of course! Friday afternoon brain failure. Thanks, it works now.

    Anyone needing to do this just do this:

    1. //Create a variable
    2. $page_title = perch_pages_title(true);
    3. PerchSystem::set_var('page_title',$page_title);

    Add this to your HTML page template

    1. <perch:content id="page_title" type="hidden">

    Make sure you're using perch_content_custom to render the template

    1. perch_content_custom('Your region name');


    I've created a variable using perch_pages_title, using this code:

    1. $page_title = perch_pages_title(true);
    2. PerchSystem::set_var('page_title',$page_title);

    I can test the variable is working with echo $page_title;

    I was hoping to add the page_title variable to a HTML template, like this:

    1. <perch:content id="page_title" type="text">

    But it doesn't work? A new text field appears in the CMS, pressing save does nothing.

    1. <perch:content id="page_title" type="hidden">

    Replacing type="text" with type="hidden" hides it from the CMS template.

    perch:showall shows perch_namespace, is perch:content but the id="page_title" variable isn't getting picked up?

    Using Latest Perch Runway (3.1.4)

    Any ideas?


    I'm planning a jobs listing section, I was wondering if it's possible to serve a custom 404 page if a user tries to view a job URL that has been removed from the website.

    It'd be useful to display a unique 404 page for this purpose.

    I've looked in the forums and can see mention of PerchSystem::use_error_page, is it possible to do something like this PerchSystem::use_error_page(jobs/404)

    Using Perch Runway


    Quick question about textarea and texttypes

    I've two test IDs in my page template

    1. <perch:content no-index id="textarea_test" type="textarea" label="Text area">
    2. <perch:content no-index id="text_test" type="text" label="Text">

    Before I add any content to them, I can use var_dump to see both are set to NULL

    • ["textarea_test"]=> NULL
    • ["text_test""]=> NULL

    If I add some test text and check var_dump again I can see this:

    • ["textarea_test"]=> string(21) "Test text in textarea" 
    • ["text_test"]=> string(17) "Test text in text"

    When I delete the text in both IDs only text_test returns to NULL, textarea_test returns string(0) ""  instead.

    • ["textarea_test"]=> string(0) "" 
    • ["text_test"]=> NULL

    The different way the textarea and texttypes work when content is deleted (via the CMS) threw me today. I was using isset to check the value of an ID. I added some text, then deleted it. The ID was empty, I checked with showall but because it wasn't NULL it wasn't working as expected.

    Just wondering if the textarea should also revert to NULL the same way text does?

    Summary information

    Hi hus_hmd

    Thanks for taking the time to respond, appreciated.

    This makes sense:

    Back to your code. PHP's isset() checks whether a variable has been set (i.e. has a value). If seo_description has some white space (or an empty string) then isset() would return true.

    Using var_dump($project_details);, I found seo_description had a value of ["seo_description"]=> string(0) ""

    What confused me was the if statement works the first time, because before any text is added to the CMS seo_description looks like this:

    1. ["seo_description"]=> NULL

    When seo_description is NULL the if statement works.

    Add the word "demo" to the CMS, check var_dump

    1. ["seo_description"]=> string(4) "demo"

    Delete the word "demo", I was expecting it to go back to NULL, but it doesn't.

    1. ["seo_description_test"]=> string(0) ""

    After deleting the text in the CMS, the field is no longer NULL.

    At this point isset is true (thanks for helping me understand hus_hmd).

    At least I now know why it wasn't working as expected.


    I only noticed this because I was creating a training screencast, and I deleted placeholder text in seo_description. That's when I noticed the if statement wasn't working. In reality, it's unlikely the client will do this.

    However, if it is possible to reset seo_description to NULL after the text is deleted in the CMS, it'd be handy to be able to do that.