Posts by Stephen Meehan

    Hi,


    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.

    Hi,


    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


    Code
    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:


    Code
    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?




    Summary

    Hi hus_hmd

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


    Anyone needing to do this just do this:


    Code
    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


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


    Make sure you're using perch_content_custom to render the template


    Code
    1. perch_content_custom('Your region name');

    Hi


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


    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:


    Code
    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.


    Code
    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?

    Hi,


    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

    Hi,


    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:


    Code
    1. ["seo_description"]=> NULL


    When seo_description is NULL the if statement works.




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


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


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


    Code
    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.

    Hi,


    I've simplified this post.


    seo_description is empty in the CMS, I'd expect the fallback message to show, but the page is behaving as if seo_description has a value.


    It's showing the Only show if seo_description has content in the CMS message - even though seo_description is empty?


    Code
    1. // Project meta description
    2. if (isset($project_details['0']['seo_description'])) {
    3. echo "Only show if seo_description has content in the CMS";
    4. } else {
    5. echo "This is a fallback";
    6. }


    I've checked the IDs with perch:showall and the ID seo_description is empty.


    Is there any reason why the if statement isn't working?




    /shared.php has multiple regions each one has a unique template/IDs. I've used IDs from two regions, and added them to cta--box.html.


    I was hoping to output the `IDs` from multiple regions into one template, but it's not working as expected.



    This is my setup

    Code
    1. perch_content_custom(['name', 'phone'], [
    2. 'page'=>'/shared.php',
    3. 'template'=>'_global/cta--box.html',
    4. ]);


    _global/cta--box.html

    Code
    1. <div class="contact-details">
    2. NAME: <perch:content id="name" type="text"></br>
    3. PHONE: <perch:content id="phone" type="text">
    4. </div>



    Source/output looks like this:


    Code
    1. <div class="contact-details">
    2. NAME: Janet Wilson</br>
    3. PHONE: <!-- missing phone? -->
    4. </div>
    5. <div class="contact-details">
    6. NAME: <!-- missing name? --></br>
    7. PHONE: 0123 456 7890
    8. </div>


    It's like perch_content_custom is handling each region separately, and then applying the template to each region. If I add more regions to perch_content_custom the number of times the template is repeated is the same.


    I've tried using count => 1 with perch_content_custom that stops the repeating problem, but doesn't fix the missing content?



    What's the best way to approach this?





    Summary information